hdac_hdmi.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * hdac_hdmi.c - ASoc HDA-HDMI codec driver for Intel platforms
  4. *
  5. * Copyright (C) 2014-2015 Intel Corp
  6. * Author: Samreen Nilofer <[email protected]>
  7. * Subhransu S. Prusty <[email protected]>
  8. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. *
  10. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. */
  12. #include <linux/init.h>
  13. #include <linux/delay.h>
  14. #include <linux/module.h>
  15. #include <linux/pm_runtime.h>
  16. #include <linux/hdmi.h>
  17. #include <drm/drm_edid.h>
  18. #include <sound/pcm_params.h>
  19. #include <sound/jack.h>
  20. #include <sound/soc.h>
  21. #include <sound/hdaudio_ext.h>
  22. #include <sound/hda_i915.h>
  23. #include <sound/pcm_drm_eld.h>
  24. #include <sound/hda_chmap.h>
  25. #include "../../hda/local.h"
  26. #include "hdac_hdmi.h"
  27. #define NAME_SIZE 32
  28. #define AMP_OUT_MUTE 0xb080
  29. #define AMP_OUT_UNMUTE 0xb000
  30. #define PIN_OUT (AC_PINCTL_OUT_EN)
  31. #define HDA_MAX_CONNECTIONS 32
  32. #define HDA_MAX_CVTS 3
  33. #define HDA_MAX_PORTS 3
  34. #define ELD_MAX_SIZE 256
  35. #define ELD_FIXED_BYTES 20
  36. #define ELD_VER_CEA_861D 2
  37. #define ELD_VER_PARTIAL 31
  38. #define ELD_MAX_MNL 16
  39. struct hdac_hdmi_cvt_params {
  40. unsigned int channels_min;
  41. unsigned int channels_max;
  42. u32 rates;
  43. u64 formats;
  44. unsigned int maxbps;
  45. };
  46. struct hdac_hdmi_cvt {
  47. struct list_head head;
  48. hda_nid_t nid;
  49. const char *name;
  50. struct hdac_hdmi_cvt_params params;
  51. };
  52. /* Currently only spk_alloc, more to be added */
  53. struct hdac_hdmi_parsed_eld {
  54. u8 spk_alloc;
  55. };
  56. struct hdac_hdmi_eld {
  57. bool monitor_present;
  58. bool eld_valid;
  59. int eld_size;
  60. char eld_buffer[ELD_MAX_SIZE];
  61. struct hdac_hdmi_parsed_eld info;
  62. };
  63. struct hdac_hdmi_pin {
  64. struct list_head head;
  65. hda_nid_t nid;
  66. bool mst_capable;
  67. struct hdac_hdmi_port *ports;
  68. int num_ports;
  69. struct hdac_device *hdev;
  70. };
  71. struct hdac_hdmi_port {
  72. struct list_head head;
  73. int id;
  74. struct hdac_hdmi_pin *pin;
  75. int num_mux_nids;
  76. hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
  77. struct hdac_hdmi_eld eld;
  78. const char *jack_pin;
  79. bool is_connect;
  80. struct snd_soc_dapm_context *dapm;
  81. const char *output_pin;
  82. struct work_struct dapm_work;
  83. };
  84. struct hdac_hdmi_pcm {
  85. struct list_head head;
  86. int pcm_id;
  87. struct list_head port_list;
  88. struct hdac_hdmi_cvt *cvt;
  89. struct snd_soc_jack *jack;
  90. int stream_tag;
  91. int channels;
  92. int format;
  93. bool chmap_set;
  94. unsigned char chmap[8]; /* ALSA API channel-map */
  95. struct mutex lock;
  96. int jack_event;
  97. struct snd_kcontrol *eld_ctl;
  98. };
  99. struct hdac_hdmi_dai_port_map {
  100. int dai_id;
  101. struct hdac_hdmi_port *port;
  102. struct hdac_hdmi_cvt *cvt;
  103. };
  104. struct hdac_hdmi_drv_data {
  105. unsigned int vendor_nid;
  106. };
  107. struct hdac_hdmi_priv {
  108. struct hdac_device *hdev;
  109. struct snd_soc_component *component;
  110. struct snd_card *card;
  111. struct hdac_hdmi_dai_port_map dai_map[HDA_MAX_CVTS];
  112. struct list_head pin_list;
  113. struct list_head cvt_list;
  114. struct list_head pcm_list;
  115. int num_pin;
  116. int num_cvt;
  117. int num_ports;
  118. struct mutex pin_mutex;
  119. struct hdac_chmap chmap;
  120. struct hdac_hdmi_drv_data *drv_data;
  121. struct snd_soc_dai_driver *dai_drv;
  122. };
  123. #define hdev_to_hdmi_priv(_hdev) dev_get_drvdata(&(_hdev)->dev)
  124. static struct hdac_hdmi_pcm *
  125. hdac_hdmi_get_pcm_from_cvt(struct hdac_hdmi_priv *hdmi,
  126. struct hdac_hdmi_cvt *cvt)
  127. {
  128. struct hdac_hdmi_pcm *pcm;
  129. list_for_each_entry(pcm, &hdmi->pcm_list, head) {
  130. if (pcm->cvt == cvt)
  131. return pcm;
  132. }
  133. return NULL;
  134. }
  135. static void hdac_hdmi_jack_report(struct hdac_hdmi_pcm *pcm,
  136. struct hdac_hdmi_port *port, bool is_connect)
  137. {
  138. struct hdac_device *hdev = port->pin->hdev;
  139. port->is_connect = is_connect;
  140. if (is_connect) {
  141. /*
  142. * Report Jack connect event when a device is connected
  143. * for the first time where same PCM is attached to multiple
  144. * ports.
  145. */
  146. if (pcm->jack_event == 0) {
  147. dev_dbg(&hdev->dev,
  148. "jack report for pcm=%d\n",
  149. pcm->pcm_id);
  150. snd_soc_jack_report(pcm->jack, SND_JACK_AVOUT,
  151. SND_JACK_AVOUT);
  152. }
  153. pcm->jack_event++;
  154. } else {
  155. /*
  156. * Report Jack disconnect event when a device is disconnected
  157. * is the only last connected device when same PCM is attached
  158. * to multiple ports.
  159. */
  160. if (pcm->jack_event == 1)
  161. snd_soc_jack_report(pcm->jack, 0, SND_JACK_AVOUT);
  162. if (pcm->jack_event > 0)
  163. pcm->jack_event--;
  164. }
  165. }
  166. static void hdac_hdmi_port_dapm_update(struct hdac_hdmi_port *port)
  167. {
  168. if (port->is_connect)
  169. snd_soc_dapm_enable_pin(port->dapm, port->jack_pin);
  170. else
  171. snd_soc_dapm_disable_pin(port->dapm, port->jack_pin);
  172. snd_soc_dapm_sync(port->dapm);
  173. }
  174. static void hdac_hdmi_jack_dapm_work(struct work_struct *work)
  175. {
  176. struct hdac_hdmi_port *port;
  177. port = container_of(work, struct hdac_hdmi_port, dapm_work);
  178. hdac_hdmi_port_dapm_update(port);
  179. }
  180. static void hdac_hdmi_jack_report_sync(struct hdac_hdmi_pcm *pcm,
  181. struct hdac_hdmi_port *port, bool is_connect)
  182. {
  183. hdac_hdmi_jack_report(pcm, port, is_connect);
  184. hdac_hdmi_port_dapm_update(port);
  185. }
  186. /* MST supported verbs */
  187. /*
  188. * Get the no devices that can be connected to a port on the Pin widget.
  189. */
  190. static int hdac_hdmi_get_port_len(struct hdac_device *hdev, hda_nid_t nid)
  191. {
  192. unsigned int caps;
  193. unsigned int type, param;
  194. caps = get_wcaps(hdev, nid);
  195. type = get_wcaps_type(caps);
  196. if (!(caps & AC_WCAP_DIGITAL) || (type != AC_WID_PIN))
  197. return 0;
  198. param = snd_hdac_read_parm_uncached(hdev, nid, AC_PAR_DEVLIST_LEN);
  199. if (param == -1)
  200. return param;
  201. return param & AC_DEV_LIST_LEN_MASK;
  202. }
  203. /*
  204. * Get the port entry select on the pin. Return the port entry
  205. * id selected on the pin. Return 0 means the first port entry
  206. * is selected or MST is not supported.
  207. */
  208. static int hdac_hdmi_port_select_get(struct hdac_device *hdev,
  209. struct hdac_hdmi_port *port)
  210. {
  211. return snd_hdac_codec_read(hdev, port->pin->nid,
  212. 0, AC_VERB_GET_DEVICE_SEL, 0);
  213. }
  214. /*
  215. * Sets the selected port entry for the configuring Pin widget verb.
  216. * returns error if port set is not equal to port get otherwise success
  217. */
  218. static int hdac_hdmi_port_select_set(struct hdac_device *hdev,
  219. struct hdac_hdmi_port *port)
  220. {
  221. int num_ports;
  222. if (!port->pin->mst_capable)
  223. return 0;
  224. /* AC_PAR_DEVLIST_LEN is 0 based. */
  225. num_ports = hdac_hdmi_get_port_len(hdev, port->pin->nid);
  226. if (num_ports < 0)
  227. return -EIO;
  228. /*
  229. * Device List Length is a 0 based integer value indicating the
  230. * number of sink device that a MST Pin Widget can support.
  231. */
  232. if (num_ports + 1 < port->id)
  233. return 0;
  234. snd_hdac_codec_write(hdev, port->pin->nid, 0,
  235. AC_VERB_SET_DEVICE_SEL, port->id);
  236. if (port->id != hdac_hdmi_port_select_get(hdev, port))
  237. return -EIO;
  238. dev_dbg(&hdev->dev, "Selected the port=%d\n", port->id);
  239. return 0;
  240. }
  241. static struct hdac_hdmi_pcm *get_hdmi_pcm_from_id(struct hdac_hdmi_priv *hdmi,
  242. int pcm_idx)
  243. {
  244. struct hdac_hdmi_pcm *pcm;
  245. list_for_each_entry(pcm, &hdmi->pcm_list, head) {
  246. if (pcm->pcm_id == pcm_idx)
  247. return pcm;
  248. }
  249. return NULL;
  250. }
  251. static unsigned int sad_format(const u8 *sad)
  252. {
  253. return ((sad[0] >> 0x3) & 0x1f);
  254. }
  255. static unsigned int sad_sample_bits_lpcm(const u8 *sad)
  256. {
  257. return (sad[2] & 7);
  258. }
  259. static int hdac_hdmi_eld_limit_formats(struct snd_pcm_runtime *runtime,
  260. void *eld)
  261. {
  262. u64 formats = SNDRV_PCM_FMTBIT_S16;
  263. int i;
  264. const u8 *sad, *eld_buf = eld;
  265. sad = drm_eld_sad(eld_buf);
  266. if (!sad)
  267. goto format_constraint;
  268. for (i = drm_eld_sad_count(eld_buf); i > 0; i--, sad += 3) {
  269. if (sad_format(sad) == 1) { /* AUDIO_CODING_TYPE_LPCM */
  270. /*
  271. * the controller support 20 and 24 bits in 32 bit
  272. * container so we set S32
  273. */
  274. if (sad_sample_bits_lpcm(sad) & 0x6)
  275. formats |= SNDRV_PCM_FMTBIT_S32;
  276. }
  277. }
  278. format_constraint:
  279. return snd_pcm_hw_constraint_mask64(runtime, SNDRV_PCM_HW_PARAM_FORMAT,
  280. formats);
  281. }
  282. static void
  283. hdac_hdmi_set_dip_index(struct hdac_device *hdev, hda_nid_t pin_nid,
  284. int packet_index, int byte_index)
  285. {
  286. int val;
  287. val = (packet_index << 5) | (byte_index & 0x1f);
  288. snd_hdac_codec_write(hdev, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
  289. }
  290. struct dp_audio_infoframe {
  291. u8 type; /* 0x84 */
  292. u8 len; /* 0x1b */
  293. u8 ver; /* 0x11 << 2 */
  294. u8 CC02_CT47; /* match with HDMI infoframe from this on */
  295. u8 SS01_SF24;
  296. u8 CXT04;
  297. u8 CA;
  298. u8 LFEPBL01_LSV36_DM_INH7;
  299. };
  300. static int hdac_hdmi_setup_audio_infoframe(struct hdac_device *hdev,
  301. struct hdac_hdmi_pcm *pcm, struct hdac_hdmi_port *port)
  302. {
  303. uint8_t buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AUDIO_INFOFRAME_SIZE];
  304. struct hdmi_audio_infoframe frame;
  305. struct hdac_hdmi_pin *pin = port->pin;
  306. struct dp_audio_infoframe dp_ai;
  307. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  308. struct hdac_hdmi_cvt *cvt = pcm->cvt;
  309. u8 *dip;
  310. int ret;
  311. int i;
  312. const u8 *eld_buf;
  313. u8 conn_type;
  314. int channels, ca;
  315. ca = snd_hdac_channel_allocation(hdev, port->eld.info.spk_alloc,
  316. pcm->channels, pcm->chmap_set, true, pcm->chmap);
  317. channels = snd_hdac_get_active_channels(ca);
  318. hdmi->chmap.ops.set_channel_count(hdev, cvt->nid, channels);
  319. snd_hdac_setup_channel_mapping(&hdmi->chmap, pin->nid, false, ca,
  320. pcm->channels, pcm->chmap, pcm->chmap_set);
  321. eld_buf = port->eld.eld_buffer;
  322. conn_type = drm_eld_get_conn_type(eld_buf);
  323. switch (conn_type) {
  324. case DRM_ELD_CONN_TYPE_HDMI:
  325. hdmi_audio_infoframe_init(&frame);
  326. frame.channels = channels;
  327. frame.channel_allocation = ca;
  328. ret = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
  329. if (ret < 0)
  330. return ret;
  331. break;
  332. case DRM_ELD_CONN_TYPE_DP:
  333. memset(&dp_ai, 0, sizeof(dp_ai));
  334. dp_ai.type = 0x84;
  335. dp_ai.len = 0x1b;
  336. dp_ai.ver = 0x11 << 2;
  337. dp_ai.CC02_CT47 = channels - 1;
  338. dp_ai.CA = ca;
  339. dip = (u8 *)&dp_ai;
  340. break;
  341. default:
  342. dev_err(&hdev->dev, "Invalid connection type: %d\n", conn_type);
  343. return -EIO;
  344. }
  345. /* stop infoframe transmission */
  346. hdac_hdmi_set_dip_index(hdev, pin->nid, 0x0, 0x0);
  347. snd_hdac_codec_write(hdev, pin->nid, 0,
  348. AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_DISABLE);
  349. /* Fill infoframe. Index auto-incremented */
  350. hdac_hdmi_set_dip_index(hdev, pin->nid, 0x0, 0x0);
  351. if (conn_type == DRM_ELD_CONN_TYPE_HDMI) {
  352. for (i = 0; i < sizeof(buffer); i++)
  353. snd_hdac_codec_write(hdev, pin->nid, 0,
  354. AC_VERB_SET_HDMI_DIP_DATA, buffer[i]);
  355. } else {
  356. for (i = 0; i < sizeof(dp_ai); i++)
  357. snd_hdac_codec_write(hdev, pin->nid, 0,
  358. AC_VERB_SET_HDMI_DIP_DATA, dip[i]);
  359. }
  360. /* Start infoframe */
  361. hdac_hdmi_set_dip_index(hdev, pin->nid, 0x0, 0x0);
  362. snd_hdac_codec_write(hdev, pin->nid, 0,
  363. AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_BEST);
  364. return 0;
  365. }
  366. static int hdac_hdmi_set_stream(struct snd_soc_dai *dai,
  367. void *stream, int direction)
  368. {
  369. struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
  370. struct hdac_device *hdev = hdmi->hdev;
  371. struct hdac_hdmi_dai_port_map *dai_map;
  372. struct hdac_hdmi_pcm *pcm;
  373. struct hdac_stream *hstream;
  374. if (!stream)
  375. return -EINVAL;
  376. hstream = (struct hdac_stream *)stream;
  377. dev_dbg(&hdev->dev, "%s: strm_tag: %d\n", __func__, hstream->stream_tag);
  378. dai_map = &hdmi->dai_map[dai->id];
  379. pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
  380. if (pcm)
  381. pcm->stream_tag = (hstream->stream_tag << 4);
  382. return 0;
  383. }
  384. static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,
  385. struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)
  386. {
  387. struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
  388. struct hdac_hdmi_dai_port_map *dai_map;
  389. struct hdac_hdmi_pcm *pcm;
  390. int format;
  391. dai_map = &hdmi->dai_map[dai->id];
  392. format = snd_hdac_calc_stream_format(params_rate(hparams),
  393. params_channels(hparams), params_format(hparams),
  394. dai->driver->playback.sig_bits, 0);
  395. pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
  396. if (!pcm)
  397. return -EIO;
  398. pcm->format = format;
  399. pcm->channels = params_channels(hparams);
  400. return 0;
  401. }
  402. static int hdac_hdmi_query_port_connlist(struct hdac_device *hdev,
  403. struct hdac_hdmi_pin *pin,
  404. struct hdac_hdmi_port *port)
  405. {
  406. if (!(get_wcaps(hdev, pin->nid) & AC_WCAP_CONN_LIST)) {
  407. dev_warn(&hdev->dev,
  408. "HDMI: pin %d wcaps %#x does not support connection list\n",
  409. pin->nid, get_wcaps(hdev, pin->nid));
  410. return -EINVAL;
  411. }
  412. if (hdac_hdmi_port_select_set(hdev, port) < 0)
  413. return -EIO;
  414. port->num_mux_nids = snd_hdac_get_connections(hdev, pin->nid,
  415. port->mux_nids, HDA_MAX_CONNECTIONS);
  416. if (port->num_mux_nids == 0)
  417. dev_warn(&hdev->dev,
  418. "No connections found for pin:port %d:%d\n",
  419. pin->nid, port->id);
  420. dev_dbg(&hdev->dev, "num_mux_nids %d for pin:port %d:%d\n",
  421. port->num_mux_nids, pin->nid, port->id);
  422. return port->num_mux_nids;
  423. }
  424. /*
  425. * Query pcm list and return port to which stream is routed.
  426. *
  427. * Also query connection list of the pin, to validate the cvt to port map.
  428. *
  429. * Same stream rendering to multiple ports simultaneously can be done
  430. * possibly, but not supported for now in driver. So return the first port
  431. * connected.
  432. */
  433. static struct hdac_hdmi_port *hdac_hdmi_get_port_from_cvt(
  434. struct hdac_device *hdev,
  435. struct hdac_hdmi_priv *hdmi,
  436. struct hdac_hdmi_cvt *cvt)
  437. {
  438. struct hdac_hdmi_pcm *pcm;
  439. struct hdac_hdmi_port *port;
  440. int ret, i;
  441. list_for_each_entry(pcm, &hdmi->pcm_list, head) {
  442. if (pcm->cvt == cvt) {
  443. if (list_empty(&pcm->port_list))
  444. continue;
  445. list_for_each_entry(port, &pcm->port_list, head) {
  446. mutex_lock(&pcm->lock);
  447. ret = hdac_hdmi_query_port_connlist(hdev,
  448. port->pin, port);
  449. mutex_unlock(&pcm->lock);
  450. if (ret < 0)
  451. continue;
  452. for (i = 0; i < port->num_mux_nids; i++) {
  453. if (port->mux_nids[i] == cvt->nid &&
  454. port->eld.monitor_present &&
  455. port->eld.eld_valid)
  456. return port;
  457. }
  458. }
  459. }
  460. }
  461. return NULL;
  462. }
  463. /*
  464. * Go through all converters and ensure connection is set to
  465. * the correct pin as set via kcontrols.
  466. */
  467. static void hdac_hdmi_verify_connect_sel_all_pins(struct hdac_device *hdev)
  468. {
  469. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  470. struct hdac_hdmi_port *port;
  471. struct hdac_hdmi_cvt *cvt;
  472. int cvt_idx = 0;
  473. list_for_each_entry(cvt, &hdmi->cvt_list, head) {
  474. port = hdac_hdmi_get_port_from_cvt(hdev, hdmi, cvt);
  475. if (port && port->pin) {
  476. snd_hdac_codec_write(hdev, port->pin->nid, 0,
  477. AC_VERB_SET_CONNECT_SEL, cvt_idx);
  478. dev_dbg(&hdev->dev, "%s: %s set connect %d -> %d\n",
  479. __func__, cvt->name, port->pin->nid, cvt_idx);
  480. }
  481. ++cvt_idx;
  482. }
  483. }
  484. /*
  485. * This tries to get a valid pin and set the HW constraints based on the
  486. * ELD. Even if a valid pin is not found return success so that device open
  487. * doesn't fail.
  488. */
  489. static int hdac_hdmi_pcm_open(struct snd_pcm_substream *substream,
  490. struct snd_soc_dai *dai)
  491. {
  492. struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
  493. struct hdac_device *hdev = hdmi->hdev;
  494. struct hdac_hdmi_dai_port_map *dai_map;
  495. struct hdac_hdmi_cvt *cvt;
  496. struct hdac_hdmi_port *port;
  497. int ret;
  498. dai_map = &hdmi->dai_map[dai->id];
  499. cvt = dai_map->cvt;
  500. port = hdac_hdmi_get_port_from_cvt(hdev, hdmi, cvt);
  501. /*
  502. * To make PA and other userland happy.
  503. * userland scans devices so returning error does not help.
  504. */
  505. if (!port)
  506. return 0;
  507. if ((!port->eld.monitor_present) ||
  508. (!port->eld.eld_valid)) {
  509. dev_warn(&hdev->dev,
  510. "Failed: present?:%d ELD valid?:%d pin:port: %d:%d\n",
  511. port->eld.monitor_present, port->eld.eld_valid,
  512. port->pin->nid, port->id);
  513. return 0;
  514. }
  515. dai_map->port = port;
  516. ret = hdac_hdmi_eld_limit_formats(substream->runtime,
  517. port->eld.eld_buffer);
  518. if (ret < 0)
  519. return ret;
  520. return snd_pcm_hw_constraint_eld(substream->runtime,
  521. port->eld.eld_buffer);
  522. }
  523. static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,
  524. struct snd_soc_dai *dai)
  525. {
  526. struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
  527. struct hdac_hdmi_dai_port_map *dai_map;
  528. struct hdac_hdmi_pcm *pcm;
  529. dai_map = &hdmi->dai_map[dai->id];
  530. pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
  531. if (pcm) {
  532. mutex_lock(&pcm->lock);
  533. pcm->chmap_set = false;
  534. memset(pcm->chmap, 0, sizeof(pcm->chmap));
  535. pcm->channels = 0;
  536. mutex_unlock(&pcm->lock);
  537. }
  538. if (dai_map->port)
  539. dai_map->port = NULL;
  540. }
  541. static int
  542. hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct hdac_hdmi_cvt *cvt)
  543. {
  544. unsigned int chans;
  545. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  546. int err;
  547. chans = get_wcaps(hdev, cvt->nid);
  548. chans = get_wcaps_channels(chans);
  549. cvt->params.channels_min = 2;
  550. cvt->params.channels_max = chans;
  551. if (chans > hdmi->chmap.channels_max)
  552. hdmi->chmap.channels_max = chans;
  553. err = snd_hdac_query_supported_pcm(hdev, cvt->nid,
  554. &cvt->params.rates,
  555. &cvt->params.formats,
  556. &cvt->params.maxbps);
  557. if (err < 0)
  558. dev_err(&hdev->dev,
  559. "Failed to query pcm params for nid %d: %d\n",
  560. cvt->nid, err);
  561. return err;
  562. }
  563. static int hdac_hdmi_fill_widget_info(struct device *dev,
  564. struct snd_soc_dapm_widget *w, enum snd_soc_dapm_type id,
  565. void *priv, const char *wname, const char *stream,
  566. struct snd_kcontrol_new *wc, int numkc,
  567. int (*event)(struct snd_soc_dapm_widget *,
  568. struct snd_kcontrol *, int), unsigned short event_flags)
  569. {
  570. w->id = id;
  571. w->name = devm_kstrdup(dev, wname, GFP_KERNEL);
  572. if (!w->name)
  573. return -ENOMEM;
  574. w->sname = stream;
  575. w->reg = SND_SOC_NOPM;
  576. w->shift = 0;
  577. w->kcontrol_news = wc;
  578. w->num_kcontrols = numkc;
  579. w->priv = priv;
  580. w->event = event;
  581. w->event_flags = event_flags;
  582. return 0;
  583. }
  584. static void hdac_hdmi_fill_route(struct snd_soc_dapm_route *route,
  585. const char *sink, const char *control, const char *src,
  586. int (*handler)(struct snd_soc_dapm_widget *src,
  587. struct snd_soc_dapm_widget *sink))
  588. {
  589. route->sink = sink;
  590. route->source = src;
  591. route->control = control;
  592. route->connected = handler;
  593. }
  594. static struct hdac_hdmi_pcm *hdac_hdmi_get_pcm(struct hdac_device *hdev,
  595. struct hdac_hdmi_port *port)
  596. {
  597. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  598. struct hdac_hdmi_pcm *pcm;
  599. struct hdac_hdmi_port *p;
  600. list_for_each_entry(pcm, &hdmi->pcm_list, head) {
  601. if (list_empty(&pcm->port_list))
  602. continue;
  603. list_for_each_entry(p, &pcm->port_list, head) {
  604. if (p->id == port->id && port->pin == p->pin)
  605. return pcm;
  606. }
  607. }
  608. return NULL;
  609. }
  610. static void hdac_hdmi_set_power_state(struct hdac_device *hdev,
  611. hda_nid_t nid, unsigned int pwr_state)
  612. {
  613. int count;
  614. unsigned int state;
  615. if (get_wcaps(hdev, nid) & AC_WCAP_POWER) {
  616. if (!snd_hdac_check_power_state(hdev, nid, pwr_state)) {
  617. for (count = 0; count < 10; count++) {
  618. snd_hdac_codec_read(hdev, nid, 0,
  619. AC_VERB_SET_POWER_STATE,
  620. pwr_state);
  621. state = snd_hdac_sync_power_state(hdev,
  622. nid, pwr_state);
  623. if (!(state & AC_PWRST_ERROR))
  624. break;
  625. }
  626. }
  627. }
  628. }
  629. static void hdac_hdmi_set_amp(struct hdac_device *hdev,
  630. hda_nid_t nid, int val)
  631. {
  632. if (get_wcaps(hdev, nid) & AC_WCAP_OUT_AMP)
  633. snd_hdac_codec_write(hdev, nid, 0,
  634. AC_VERB_SET_AMP_GAIN_MUTE, val);
  635. }
  636. static int hdac_hdmi_pin_output_widget_event(struct snd_soc_dapm_widget *w,
  637. struct snd_kcontrol *kc, int event)
  638. {
  639. struct hdac_hdmi_port *port = w->priv;
  640. struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev);
  641. struct hdac_hdmi_pcm *pcm;
  642. dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n",
  643. __func__, w->name, event);
  644. pcm = hdac_hdmi_get_pcm(hdev, port);
  645. if (!pcm)
  646. return -EIO;
  647. /* set the device if pin is mst_capable */
  648. if (hdac_hdmi_port_select_set(hdev, port) < 0)
  649. return -EIO;
  650. switch (event) {
  651. case SND_SOC_DAPM_PRE_PMU:
  652. hdac_hdmi_set_power_state(hdev, port->pin->nid, AC_PWRST_D0);
  653. /* Enable out path for this pin widget */
  654. snd_hdac_codec_write(hdev, port->pin->nid, 0,
  655. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
  656. hdac_hdmi_set_amp(hdev, port->pin->nid, AMP_OUT_UNMUTE);
  657. return hdac_hdmi_setup_audio_infoframe(hdev, pcm, port);
  658. case SND_SOC_DAPM_POST_PMD:
  659. hdac_hdmi_set_amp(hdev, port->pin->nid, AMP_OUT_MUTE);
  660. /* Disable out path for this pin widget */
  661. snd_hdac_codec_write(hdev, port->pin->nid, 0,
  662. AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
  663. hdac_hdmi_set_power_state(hdev, port->pin->nid, AC_PWRST_D3);
  664. break;
  665. }
  666. return 0;
  667. }
  668. static int hdac_hdmi_cvt_output_widget_event(struct snd_soc_dapm_widget *w,
  669. struct snd_kcontrol *kc, int event)
  670. {
  671. struct hdac_hdmi_cvt *cvt = w->priv;
  672. struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev);
  673. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  674. struct hdac_hdmi_pcm *pcm;
  675. dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n",
  676. __func__, w->name, event);
  677. pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, cvt);
  678. if (!pcm)
  679. return -EIO;
  680. switch (event) {
  681. case SND_SOC_DAPM_PRE_PMU:
  682. hdac_hdmi_set_power_state(hdev, cvt->nid, AC_PWRST_D0);
  683. /* Enable transmission */
  684. snd_hdac_codec_write(hdev, cvt->nid, 0,
  685. AC_VERB_SET_DIGI_CONVERT_1, 1);
  686. /* Category Code (CC) to zero */
  687. snd_hdac_codec_write(hdev, cvt->nid, 0,
  688. AC_VERB_SET_DIGI_CONVERT_2, 0);
  689. snd_hdac_codec_write(hdev, cvt->nid, 0,
  690. AC_VERB_SET_CHANNEL_STREAMID, pcm->stream_tag);
  691. snd_hdac_codec_write(hdev, cvt->nid, 0,
  692. AC_VERB_SET_STREAM_FORMAT, pcm->format);
  693. /*
  694. * The connection indices are shared by all converters and
  695. * may interfere with each other. Ensure correct
  696. * routing for all converters at stream start.
  697. */
  698. hdac_hdmi_verify_connect_sel_all_pins(hdev);
  699. break;
  700. case SND_SOC_DAPM_POST_PMD:
  701. snd_hdac_codec_write(hdev, cvt->nid, 0,
  702. AC_VERB_SET_CHANNEL_STREAMID, 0);
  703. snd_hdac_codec_write(hdev, cvt->nid, 0,
  704. AC_VERB_SET_STREAM_FORMAT, 0);
  705. hdac_hdmi_set_power_state(hdev, cvt->nid, AC_PWRST_D3);
  706. break;
  707. }
  708. return 0;
  709. }
  710. static int hdac_hdmi_pin_mux_widget_event(struct snd_soc_dapm_widget *w,
  711. struct snd_kcontrol *kc, int event)
  712. {
  713. struct hdac_hdmi_port *port = w->priv;
  714. struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev);
  715. int mux_idx;
  716. dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n",
  717. __func__, w->name, event);
  718. if (!kc)
  719. kc = w->kcontrols[0];
  720. mux_idx = dapm_kcontrol_get_value(kc);
  721. /* set the device if pin is mst_capable */
  722. if (hdac_hdmi_port_select_set(hdev, port) < 0)
  723. return -EIO;
  724. if (mux_idx > 0) {
  725. snd_hdac_codec_write(hdev, port->pin->nid, 0,
  726. AC_VERB_SET_CONNECT_SEL, (mux_idx - 1));
  727. }
  728. return 0;
  729. }
  730. /*
  731. * Based on user selection, map the PINs with the PCMs.
  732. */
  733. static int hdac_hdmi_set_pin_port_mux(struct snd_kcontrol *kcontrol,
  734. struct snd_ctl_elem_value *ucontrol)
  735. {
  736. int ret;
  737. struct hdac_hdmi_port *p, *p_next;
  738. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  739. struct snd_soc_dapm_widget *w = snd_soc_dapm_kcontrol_widget(kcontrol);
  740. struct snd_soc_dapm_context *dapm = w->dapm;
  741. struct hdac_hdmi_port *port = w->priv;
  742. struct hdac_device *hdev = dev_to_hdac_dev(dapm->dev);
  743. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  744. struct hdac_hdmi_pcm *pcm;
  745. const char *cvt_name = e->texts[ucontrol->value.enumerated.item[0]];
  746. ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  747. if (ret < 0)
  748. return ret;
  749. if (port == NULL)
  750. return -EINVAL;
  751. mutex_lock(&hdmi->pin_mutex);
  752. list_for_each_entry(pcm, &hdmi->pcm_list, head) {
  753. if (list_empty(&pcm->port_list))
  754. continue;
  755. list_for_each_entry_safe(p, p_next, &pcm->port_list, head) {
  756. if (p == port && p->id == port->id &&
  757. p->pin == port->pin) {
  758. hdac_hdmi_jack_report_sync(pcm, port, false);
  759. list_del(&p->head);
  760. }
  761. }
  762. }
  763. /*
  764. * Jack status is not reported during device probe as the
  765. * PCMs are not registered by then. So report it here.
  766. */
  767. list_for_each_entry(pcm, &hdmi->pcm_list, head) {
  768. if (!strcmp(cvt_name, pcm->cvt->name)) {
  769. list_add_tail(&port->head, &pcm->port_list);
  770. if (port->eld.monitor_present && port->eld.eld_valid) {
  771. hdac_hdmi_jack_report_sync(pcm, port, true);
  772. mutex_unlock(&hdmi->pin_mutex);
  773. return ret;
  774. }
  775. }
  776. }
  777. mutex_unlock(&hdmi->pin_mutex);
  778. return ret;
  779. }
  780. /*
  781. * Ideally the Mux inputs should be based on the num_muxs enumerated, but
  782. * the display driver seem to be programming the connection list for the pin
  783. * widget runtime.
  784. *
  785. * So programming all the possible inputs for the mux, the user has to take
  786. * care of selecting the right one and leaving all other inputs selected to
  787. * "NONE"
  788. */
  789. static int hdac_hdmi_create_pin_port_muxs(struct hdac_device *hdev,
  790. struct hdac_hdmi_port *port,
  791. struct snd_soc_dapm_widget *widget,
  792. const char *widget_name)
  793. {
  794. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  795. struct hdac_hdmi_pin *pin = port->pin;
  796. struct snd_kcontrol_new *kc;
  797. struct hdac_hdmi_cvt *cvt;
  798. struct soc_enum *se;
  799. char kc_name[NAME_SIZE];
  800. char mux_items[NAME_SIZE];
  801. /* To hold inputs to the Pin mux */
  802. char *items[HDA_MAX_CONNECTIONS];
  803. int i = 0;
  804. int num_items = hdmi->num_cvt + 1;
  805. kc = devm_kzalloc(&hdev->dev, sizeof(*kc), GFP_KERNEL);
  806. if (!kc)
  807. return -ENOMEM;
  808. se = devm_kzalloc(&hdev->dev, sizeof(*se), GFP_KERNEL);
  809. if (!se)
  810. return -ENOMEM;
  811. snprintf(kc_name, NAME_SIZE, "Pin %d port %d Input",
  812. pin->nid, port->id);
  813. kc->name = devm_kstrdup(&hdev->dev, kc_name, GFP_KERNEL);
  814. if (!kc->name)
  815. return -ENOMEM;
  816. kc->private_value = (long)se;
  817. kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  818. kc->access = 0;
  819. kc->info = snd_soc_info_enum_double;
  820. kc->put = hdac_hdmi_set_pin_port_mux;
  821. kc->get = snd_soc_dapm_get_enum_double;
  822. se->reg = SND_SOC_NOPM;
  823. /* enum texts: ["NONE", "cvt #", "cvt #", ...] */
  824. se->items = num_items;
  825. se->mask = roundup_pow_of_two(se->items) - 1;
  826. sprintf(mux_items, "NONE");
  827. items[i] = devm_kstrdup(&hdev->dev, mux_items, GFP_KERNEL);
  828. if (!items[i])
  829. return -ENOMEM;
  830. list_for_each_entry(cvt, &hdmi->cvt_list, head) {
  831. i++;
  832. sprintf(mux_items, "cvt %d", cvt->nid);
  833. items[i] = devm_kstrdup(&hdev->dev, mux_items, GFP_KERNEL);
  834. if (!items[i])
  835. return -ENOMEM;
  836. }
  837. se->texts = devm_kmemdup(&hdev->dev, items,
  838. (num_items * sizeof(char *)), GFP_KERNEL);
  839. if (!se->texts)
  840. return -ENOMEM;
  841. return hdac_hdmi_fill_widget_info(&hdev->dev, widget,
  842. snd_soc_dapm_mux, port, widget_name, NULL, kc, 1,
  843. hdac_hdmi_pin_mux_widget_event,
  844. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_REG);
  845. }
  846. /* Add cvt <- input <- mux route map */
  847. static void hdac_hdmi_add_pinmux_cvt_route(struct hdac_device *hdev,
  848. struct snd_soc_dapm_widget *widgets,
  849. struct snd_soc_dapm_route *route, int rindex)
  850. {
  851. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  852. const struct snd_kcontrol_new *kc;
  853. struct soc_enum *se;
  854. int mux_index = hdmi->num_cvt + hdmi->num_ports;
  855. int i, j;
  856. for (i = 0; i < hdmi->num_ports; i++) {
  857. kc = widgets[mux_index].kcontrol_news;
  858. se = (struct soc_enum *)kc->private_value;
  859. for (j = 0; j < hdmi->num_cvt; j++) {
  860. hdac_hdmi_fill_route(&route[rindex],
  861. widgets[mux_index].name,
  862. se->texts[j + 1],
  863. widgets[j].name, NULL);
  864. rindex++;
  865. }
  866. mux_index++;
  867. }
  868. }
  869. /*
  870. * Widgets are added in the below sequence
  871. * Converter widgets for num converters enumerated
  872. * Pin-port widgets for num ports for Pins enumerated
  873. * Pin-port mux widgets to represent connenction list of pin widget
  874. *
  875. * For each port, one Mux and One output widget is added
  876. * Total widgets elements = num_cvt + (num_ports * 2);
  877. *
  878. * Routes are added as below:
  879. * pin-port mux -> pin (based on num_ports)
  880. * cvt -> "Input sel control" -> pin-port_mux
  881. *
  882. * Total route elements:
  883. * num_ports + (pin_muxes * num_cvt)
  884. */
  885. static int create_fill_widget_route_map(struct snd_soc_dapm_context *dapm)
  886. {
  887. struct snd_soc_dapm_widget *widgets;
  888. struct snd_soc_dapm_route *route;
  889. struct hdac_device *hdev = dev_to_hdac_dev(dapm->dev);
  890. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  891. struct snd_soc_dai_driver *dai_drv = hdmi->dai_drv;
  892. char widget_name[NAME_SIZE];
  893. struct hdac_hdmi_cvt *cvt;
  894. struct hdac_hdmi_pin *pin;
  895. int ret, i = 0, num_routes = 0, j;
  896. if (list_empty(&hdmi->cvt_list) || list_empty(&hdmi->pin_list))
  897. return -EINVAL;
  898. widgets = devm_kzalloc(dapm->dev, (sizeof(*widgets) *
  899. ((2 * hdmi->num_ports) + hdmi->num_cvt)),
  900. GFP_KERNEL);
  901. if (!widgets)
  902. return -ENOMEM;
  903. /* DAPM widgets to represent each converter widget */
  904. list_for_each_entry(cvt, &hdmi->cvt_list, head) {
  905. sprintf(widget_name, "Converter %d", cvt->nid);
  906. ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
  907. snd_soc_dapm_aif_in, cvt,
  908. widget_name, dai_drv[i].playback.stream_name, NULL, 0,
  909. hdac_hdmi_cvt_output_widget_event,
  910. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD);
  911. if (ret < 0)
  912. return ret;
  913. i++;
  914. }
  915. list_for_each_entry(pin, &hdmi->pin_list, head) {
  916. for (j = 0; j < pin->num_ports; j++) {
  917. sprintf(widget_name, "hif%d-%d Output",
  918. pin->nid, pin->ports[j].id);
  919. ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
  920. snd_soc_dapm_output, &pin->ports[j],
  921. widget_name, NULL, NULL, 0,
  922. hdac_hdmi_pin_output_widget_event,
  923. SND_SOC_DAPM_PRE_PMU |
  924. SND_SOC_DAPM_POST_PMD);
  925. if (ret < 0)
  926. return ret;
  927. pin->ports[j].output_pin = widgets[i].name;
  928. i++;
  929. }
  930. }
  931. /* DAPM widgets to represent the connection list to pin widget */
  932. list_for_each_entry(pin, &hdmi->pin_list, head) {
  933. for (j = 0; j < pin->num_ports; j++) {
  934. sprintf(widget_name, "Pin%d-Port%d Mux",
  935. pin->nid, pin->ports[j].id);
  936. ret = hdac_hdmi_create_pin_port_muxs(hdev,
  937. &pin->ports[j], &widgets[i],
  938. widget_name);
  939. if (ret < 0)
  940. return ret;
  941. i++;
  942. /* For cvt to pin_mux mapping */
  943. num_routes += hdmi->num_cvt;
  944. /* For pin_mux to pin mapping */
  945. num_routes++;
  946. }
  947. }
  948. route = devm_kzalloc(dapm->dev, (sizeof(*route) * num_routes),
  949. GFP_KERNEL);
  950. if (!route)
  951. return -ENOMEM;
  952. i = 0;
  953. /* Add pin <- NULL <- mux route map */
  954. list_for_each_entry(pin, &hdmi->pin_list, head) {
  955. for (j = 0; j < pin->num_ports; j++) {
  956. int sink_index = i + hdmi->num_cvt;
  957. int src_index = sink_index + pin->num_ports *
  958. hdmi->num_pin;
  959. hdac_hdmi_fill_route(&route[i],
  960. widgets[sink_index].name, NULL,
  961. widgets[src_index].name, NULL);
  962. i++;
  963. }
  964. }
  965. hdac_hdmi_add_pinmux_cvt_route(hdev, widgets, route, i);
  966. snd_soc_dapm_new_controls(dapm, widgets,
  967. ((2 * hdmi->num_ports) + hdmi->num_cvt));
  968. snd_soc_dapm_add_routes(dapm, route, num_routes);
  969. snd_soc_dapm_new_widgets(dapm->card);
  970. return 0;
  971. }
  972. static int hdac_hdmi_init_dai_map(struct hdac_device *hdev)
  973. {
  974. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  975. struct hdac_hdmi_dai_port_map *dai_map;
  976. struct hdac_hdmi_cvt *cvt;
  977. int dai_id = 0;
  978. if (list_empty(&hdmi->cvt_list))
  979. return -EINVAL;
  980. list_for_each_entry(cvt, &hdmi->cvt_list, head) {
  981. dai_map = &hdmi->dai_map[dai_id];
  982. dai_map->dai_id = dai_id;
  983. dai_map->cvt = cvt;
  984. dai_id++;
  985. if (dai_id == HDA_MAX_CVTS) {
  986. dev_warn(&hdev->dev,
  987. "Max dais supported: %d\n", dai_id);
  988. break;
  989. }
  990. }
  991. return 0;
  992. }
  993. static int hdac_hdmi_add_cvt(struct hdac_device *hdev, hda_nid_t nid)
  994. {
  995. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  996. struct hdac_hdmi_cvt *cvt;
  997. char name[NAME_SIZE];
  998. cvt = devm_kzalloc(&hdev->dev, sizeof(*cvt), GFP_KERNEL);
  999. if (!cvt)
  1000. return -ENOMEM;
  1001. cvt->nid = nid;
  1002. sprintf(name, "cvt %d", cvt->nid);
  1003. cvt->name = devm_kstrdup(&hdev->dev, name, GFP_KERNEL);
  1004. if (!cvt->name)
  1005. return -ENOMEM;
  1006. list_add_tail(&cvt->head, &hdmi->cvt_list);
  1007. hdmi->num_cvt++;
  1008. return hdac_hdmi_query_cvt_params(hdev, cvt);
  1009. }
  1010. static int hdac_hdmi_parse_eld(struct hdac_device *hdev,
  1011. struct hdac_hdmi_port *port)
  1012. {
  1013. unsigned int ver, mnl;
  1014. ver = (port->eld.eld_buffer[DRM_ELD_VER] & DRM_ELD_VER_MASK)
  1015. >> DRM_ELD_VER_SHIFT;
  1016. if (ver != ELD_VER_CEA_861D && ver != ELD_VER_PARTIAL) {
  1017. dev_err(&hdev->dev, "HDMI: Unknown ELD version %d\n", ver);
  1018. return -EINVAL;
  1019. }
  1020. mnl = (port->eld.eld_buffer[DRM_ELD_CEA_EDID_VER_MNL] &
  1021. DRM_ELD_MNL_MASK) >> DRM_ELD_MNL_SHIFT;
  1022. if (mnl > ELD_MAX_MNL) {
  1023. dev_err(&hdev->dev, "HDMI: MNL Invalid %d\n", mnl);
  1024. return -EINVAL;
  1025. }
  1026. port->eld.info.spk_alloc = port->eld.eld_buffer[DRM_ELD_SPEAKER];
  1027. return 0;
  1028. }
  1029. static void hdac_hdmi_present_sense(struct hdac_hdmi_pin *pin,
  1030. struct hdac_hdmi_port *port)
  1031. {
  1032. struct hdac_device *hdev = pin->hdev;
  1033. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  1034. struct hdac_hdmi_pcm *pcm;
  1035. int size = 0;
  1036. int port_id = -1;
  1037. bool eld_valid, eld_changed;
  1038. if (!hdmi)
  1039. return;
  1040. /*
  1041. * In case of non MST pin, get_eld info API expectes port
  1042. * to be -1.
  1043. */
  1044. mutex_lock(&hdmi->pin_mutex);
  1045. port->eld.monitor_present = false;
  1046. if (pin->mst_capable)
  1047. port_id = port->id;
  1048. size = snd_hdac_acomp_get_eld(hdev, pin->nid, port_id,
  1049. &port->eld.monitor_present,
  1050. port->eld.eld_buffer,
  1051. ELD_MAX_SIZE);
  1052. if (size > 0) {
  1053. size = min(size, ELD_MAX_SIZE);
  1054. if (hdac_hdmi_parse_eld(hdev, port) < 0)
  1055. size = -EINVAL;
  1056. }
  1057. eld_valid = port->eld.eld_valid;
  1058. if (size > 0) {
  1059. port->eld.eld_valid = true;
  1060. port->eld.eld_size = size;
  1061. } else {
  1062. port->eld.eld_valid = false;
  1063. port->eld.eld_size = 0;
  1064. }
  1065. eld_changed = (eld_valid != port->eld.eld_valid);
  1066. pcm = hdac_hdmi_get_pcm(hdev, port);
  1067. if (!port->eld.monitor_present || !port->eld.eld_valid) {
  1068. dev_err(&hdev->dev, "%s: disconnect for pin:port %d:%d\n",
  1069. __func__, pin->nid, port->id);
  1070. /*
  1071. * PCMs are not registered during device probe, so don't
  1072. * report jack here. It will be done in usermode mux
  1073. * control select.
  1074. */
  1075. if (pcm) {
  1076. hdac_hdmi_jack_report(pcm, port, false);
  1077. schedule_work(&port->dapm_work);
  1078. }
  1079. mutex_unlock(&hdmi->pin_mutex);
  1080. return;
  1081. }
  1082. if (port->eld.monitor_present && port->eld.eld_valid) {
  1083. if (pcm) {
  1084. hdac_hdmi_jack_report(pcm, port, true);
  1085. schedule_work(&port->dapm_work);
  1086. }
  1087. print_hex_dump_debug("ELD: ", DUMP_PREFIX_OFFSET, 16, 1,
  1088. port->eld.eld_buffer, port->eld.eld_size, false);
  1089. }
  1090. mutex_unlock(&hdmi->pin_mutex);
  1091. if (eld_changed && pcm)
  1092. snd_ctl_notify(hdmi->card,
  1093. SNDRV_CTL_EVENT_MASK_VALUE |
  1094. SNDRV_CTL_EVENT_MASK_INFO,
  1095. &pcm->eld_ctl->id);
  1096. }
  1097. static int hdac_hdmi_add_ports(struct hdac_device *hdev,
  1098. struct hdac_hdmi_pin *pin)
  1099. {
  1100. struct hdac_hdmi_port *ports;
  1101. int max_ports = HDA_MAX_PORTS;
  1102. int i;
  1103. /*
  1104. * FIXME: max_port may vary for each platform, so pass this as
  1105. * as driver data or query from i915 interface when this API is
  1106. * implemented.
  1107. */
  1108. ports = devm_kcalloc(&hdev->dev, max_ports, sizeof(*ports), GFP_KERNEL);
  1109. if (!ports)
  1110. return -ENOMEM;
  1111. for (i = 0; i < max_ports; i++) {
  1112. ports[i].id = i;
  1113. ports[i].pin = pin;
  1114. INIT_WORK(&ports[i].dapm_work, hdac_hdmi_jack_dapm_work);
  1115. }
  1116. pin->ports = ports;
  1117. pin->num_ports = max_ports;
  1118. return 0;
  1119. }
  1120. static int hdac_hdmi_add_pin(struct hdac_device *hdev, hda_nid_t nid)
  1121. {
  1122. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  1123. struct hdac_hdmi_pin *pin;
  1124. int ret;
  1125. pin = devm_kzalloc(&hdev->dev, sizeof(*pin), GFP_KERNEL);
  1126. if (!pin)
  1127. return -ENOMEM;
  1128. pin->nid = nid;
  1129. pin->mst_capable = false;
  1130. pin->hdev = hdev;
  1131. ret = hdac_hdmi_add_ports(hdev, pin);
  1132. if (ret < 0)
  1133. return ret;
  1134. list_add_tail(&pin->head, &hdmi->pin_list);
  1135. hdmi->num_pin++;
  1136. hdmi->num_ports += pin->num_ports;
  1137. return 0;
  1138. }
  1139. #define INTEL_VENDOR_NID 0x08
  1140. #define INTEL_GLK_VENDOR_NID 0x0b
  1141. #define INTEL_GET_VENDOR_VERB 0xf81
  1142. #define INTEL_SET_VENDOR_VERB 0x781
  1143. #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
  1144. #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
  1145. static void hdac_hdmi_skl_enable_all_pins(struct hdac_device *hdev)
  1146. {
  1147. unsigned int vendor_param;
  1148. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  1149. unsigned int vendor_nid = hdmi->drv_data->vendor_nid;
  1150. vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
  1151. INTEL_GET_VENDOR_VERB, 0);
  1152. if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
  1153. return;
  1154. vendor_param |= INTEL_EN_ALL_PIN_CVTS;
  1155. vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
  1156. INTEL_SET_VENDOR_VERB, vendor_param);
  1157. if (vendor_param == -1)
  1158. return;
  1159. }
  1160. static void hdac_hdmi_skl_enable_dp12(struct hdac_device *hdev)
  1161. {
  1162. unsigned int vendor_param;
  1163. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  1164. unsigned int vendor_nid = hdmi->drv_data->vendor_nid;
  1165. vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
  1166. INTEL_GET_VENDOR_VERB, 0);
  1167. if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
  1168. return;
  1169. /* enable DP1.2 mode */
  1170. vendor_param |= INTEL_EN_DP12;
  1171. vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
  1172. INTEL_SET_VENDOR_VERB, vendor_param);
  1173. if (vendor_param == -1)
  1174. return;
  1175. }
  1176. static int hdac_hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
  1177. struct snd_ctl_elem_info *uinfo)
  1178. {
  1179. struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
  1180. struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
  1181. struct hdac_hdmi_pcm *pcm;
  1182. struct hdac_hdmi_port *port;
  1183. struct hdac_hdmi_eld *eld;
  1184. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  1185. uinfo->count = 0;
  1186. pcm = get_hdmi_pcm_from_id(hdmi, kcontrol->id.device);
  1187. if (!pcm) {
  1188. dev_dbg(component->dev, "%s: no pcm, device %d\n", __func__,
  1189. kcontrol->id.device);
  1190. return 0;
  1191. }
  1192. if (list_empty(&pcm->port_list)) {
  1193. dev_dbg(component->dev, "%s: empty port list, device %d\n",
  1194. __func__, kcontrol->id.device);
  1195. return 0;
  1196. }
  1197. mutex_lock(&hdmi->pin_mutex);
  1198. list_for_each_entry(port, &pcm->port_list, head) {
  1199. eld = &port->eld;
  1200. if (eld->eld_valid) {
  1201. uinfo->count = eld->eld_size;
  1202. break;
  1203. }
  1204. }
  1205. mutex_unlock(&hdmi->pin_mutex);
  1206. return 0;
  1207. }
  1208. static int hdac_hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
  1209. struct snd_ctl_elem_value *ucontrol)
  1210. {
  1211. struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
  1212. struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
  1213. struct hdac_hdmi_pcm *pcm;
  1214. struct hdac_hdmi_port *port;
  1215. struct hdac_hdmi_eld *eld;
  1216. memset(ucontrol->value.bytes.data, 0, sizeof(ucontrol->value.bytes.data));
  1217. pcm = get_hdmi_pcm_from_id(hdmi, kcontrol->id.device);
  1218. if (!pcm) {
  1219. dev_dbg(component->dev, "%s: no pcm, device %d\n", __func__,
  1220. kcontrol->id.device);
  1221. return 0;
  1222. }
  1223. if (list_empty(&pcm->port_list)) {
  1224. dev_dbg(component->dev, "%s: empty port list, device %d\n",
  1225. __func__, kcontrol->id.device);
  1226. return 0;
  1227. }
  1228. mutex_lock(&hdmi->pin_mutex);
  1229. list_for_each_entry(port, &pcm->port_list, head) {
  1230. eld = &port->eld;
  1231. if (!eld->eld_valid)
  1232. continue;
  1233. if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data) ||
  1234. eld->eld_size > ELD_MAX_SIZE) {
  1235. mutex_unlock(&hdmi->pin_mutex);
  1236. dev_err(component->dev, "%s: buffer too small, device %d eld_size %d\n",
  1237. __func__, kcontrol->id.device, eld->eld_size);
  1238. snd_BUG();
  1239. return -EINVAL;
  1240. }
  1241. memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
  1242. eld->eld_size);
  1243. break;
  1244. }
  1245. mutex_unlock(&hdmi->pin_mutex);
  1246. return 0;
  1247. }
  1248. static int hdac_hdmi_create_eld_ctl(struct snd_soc_component *component, struct hdac_hdmi_pcm *pcm)
  1249. {
  1250. struct snd_kcontrol *kctl;
  1251. struct snd_kcontrol_new hdmi_eld_ctl = {
  1252. .access = SNDRV_CTL_ELEM_ACCESS_READ |
  1253. SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  1254. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1255. .name = "ELD",
  1256. .info = hdac_hdmi_eld_ctl_info,
  1257. .get = hdac_hdmi_eld_ctl_get,
  1258. .device = pcm->pcm_id,
  1259. };
  1260. /* add ELD ctl with the device number corresponding to the PCM stream */
  1261. kctl = snd_ctl_new1(&hdmi_eld_ctl, component);
  1262. if (!kctl)
  1263. return -ENOMEM;
  1264. pcm->eld_ctl = kctl;
  1265. return snd_ctl_add(component->card->snd_card, kctl);
  1266. }
  1267. static const struct snd_soc_dai_ops hdmi_dai_ops = {
  1268. .startup = hdac_hdmi_pcm_open,
  1269. .shutdown = hdac_hdmi_pcm_close,
  1270. .hw_params = hdac_hdmi_set_hw_params,
  1271. .set_stream = hdac_hdmi_set_stream,
  1272. };
  1273. /*
  1274. * Each converter can support a stream independently. So a dai is created
  1275. * based on the number of converter queried.
  1276. */
  1277. static int hdac_hdmi_create_dais(struct hdac_device *hdev,
  1278. struct snd_soc_dai_driver **dais,
  1279. struct hdac_hdmi_priv *hdmi, int num_dais)
  1280. {
  1281. struct snd_soc_dai_driver *hdmi_dais;
  1282. struct hdac_hdmi_cvt *cvt;
  1283. char name[NAME_SIZE], dai_name[NAME_SIZE];
  1284. int i = 0;
  1285. u32 rates, bps;
  1286. unsigned int rate_max = 384000, rate_min = 8000;
  1287. u64 formats;
  1288. int ret;
  1289. hdmi_dais = devm_kzalloc(&hdev->dev,
  1290. (sizeof(*hdmi_dais) * num_dais),
  1291. GFP_KERNEL);
  1292. if (!hdmi_dais)
  1293. return -ENOMEM;
  1294. list_for_each_entry(cvt, &hdmi->cvt_list, head) {
  1295. ret = snd_hdac_query_supported_pcm(hdev, cvt->nid,
  1296. &rates, &formats, &bps);
  1297. if (ret)
  1298. return ret;
  1299. /* Filter out 44.1, 88.2 and 176.4Khz */
  1300. rates &= ~(SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |
  1301. SNDRV_PCM_RATE_176400);
  1302. if (!rates)
  1303. return -EINVAL;
  1304. sprintf(dai_name, "intel-hdmi-hifi%d", i+1);
  1305. hdmi_dais[i].name = devm_kstrdup(&hdev->dev,
  1306. dai_name, GFP_KERNEL);
  1307. if (!hdmi_dais[i].name)
  1308. return -ENOMEM;
  1309. snprintf(name, sizeof(name), "hifi%d", i+1);
  1310. hdmi_dais[i].playback.stream_name =
  1311. devm_kstrdup(&hdev->dev, name, GFP_KERNEL);
  1312. if (!hdmi_dais[i].playback.stream_name)
  1313. return -ENOMEM;
  1314. /*
  1315. * Set caps based on capability queried from the converter.
  1316. * It will be constrained runtime based on ELD queried.
  1317. */
  1318. hdmi_dais[i].playback.formats = formats;
  1319. hdmi_dais[i].playback.rates = rates;
  1320. hdmi_dais[i].playback.rate_max = rate_max;
  1321. hdmi_dais[i].playback.rate_min = rate_min;
  1322. hdmi_dais[i].playback.channels_min = 2;
  1323. hdmi_dais[i].playback.channels_max = 2;
  1324. hdmi_dais[i].playback.sig_bits = bps;
  1325. hdmi_dais[i].ops = &hdmi_dai_ops;
  1326. i++;
  1327. }
  1328. *dais = hdmi_dais;
  1329. hdmi->dai_drv = hdmi_dais;
  1330. return 0;
  1331. }
  1332. /*
  1333. * Parse all nodes and store the cvt/pin nids in array
  1334. * Add one time initialization for pin and cvt widgets
  1335. */
  1336. static int hdac_hdmi_parse_and_map_nid(struct hdac_device *hdev,
  1337. struct snd_soc_dai_driver **dais, int *num_dais)
  1338. {
  1339. hda_nid_t nid;
  1340. int i, num_nodes;
  1341. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  1342. int ret;
  1343. hdac_hdmi_skl_enable_all_pins(hdev);
  1344. hdac_hdmi_skl_enable_dp12(hdev);
  1345. num_nodes = snd_hdac_get_sub_nodes(hdev, hdev->afg, &nid);
  1346. if (!nid || num_nodes <= 0) {
  1347. dev_warn(&hdev->dev, "HDMI: failed to get afg sub nodes\n");
  1348. return -EINVAL;
  1349. }
  1350. for (i = 0; i < num_nodes; i++, nid++) {
  1351. unsigned int caps;
  1352. unsigned int type;
  1353. caps = get_wcaps(hdev, nid);
  1354. type = get_wcaps_type(caps);
  1355. if (!(caps & AC_WCAP_DIGITAL))
  1356. continue;
  1357. switch (type) {
  1358. case AC_WID_AUD_OUT:
  1359. ret = hdac_hdmi_add_cvt(hdev, nid);
  1360. if (ret < 0)
  1361. return ret;
  1362. break;
  1363. case AC_WID_PIN:
  1364. ret = hdac_hdmi_add_pin(hdev, nid);
  1365. if (ret < 0)
  1366. return ret;
  1367. break;
  1368. }
  1369. }
  1370. if (!hdmi->num_pin || !hdmi->num_cvt) {
  1371. ret = -EIO;
  1372. dev_err(&hdev->dev, "Bad pin/cvt setup in %s\n", __func__);
  1373. return ret;
  1374. }
  1375. ret = hdac_hdmi_create_dais(hdev, dais, hdmi, hdmi->num_cvt);
  1376. if (ret) {
  1377. dev_err(&hdev->dev, "Failed to create dais with err: %d\n",
  1378. ret);
  1379. return ret;
  1380. }
  1381. *num_dais = hdmi->num_cvt;
  1382. ret = hdac_hdmi_init_dai_map(hdev);
  1383. if (ret < 0)
  1384. dev_err(&hdev->dev, "Failed to init DAI map with err: %d\n",
  1385. ret);
  1386. return ret;
  1387. }
  1388. static int hdac_hdmi_pin2port(void *aptr, int pin)
  1389. {
  1390. return pin - 4; /* map NID 0x05 -> port #1 */
  1391. }
  1392. static void hdac_hdmi_eld_notify_cb(void *aptr, int port, int pipe)
  1393. {
  1394. struct hdac_device *hdev = aptr;
  1395. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  1396. struct hdac_hdmi_pin *pin;
  1397. struct hdac_hdmi_port *hport = NULL;
  1398. struct snd_soc_component *component = hdmi->component;
  1399. int i;
  1400. /* Don't know how this mapping is derived */
  1401. hda_nid_t pin_nid = port + 0x04;
  1402. dev_dbg(&hdev->dev, "%s: for pin:%d port=%d\n", __func__,
  1403. pin_nid, pipe);
  1404. /*
  1405. * skip notification during system suspend (but not in runtime PM);
  1406. * the state will be updated at resume. Also since the ELD and
  1407. * connection states are updated in anyway at the end of the resume,
  1408. * we can skip it when received during PM process.
  1409. */
  1410. if (snd_power_get_state(component->card->snd_card) !=
  1411. SNDRV_CTL_POWER_D0)
  1412. return;
  1413. if (atomic_read(&hdev->in_pm))
  1414. return;
  1415. list_for_each_entry(pin, &hdmi->pin_list, head) {
  1416. if (pin->nid != pin_nid)
  1417. continue;
  1418. /* In case of non MST pin, pipe is -1 */
  1419. if (pipe == -1) {
  1420. pin->mst_capable = false;
  1421. /* if not MST, default is port[0] */
  1422. hport = &pin->ports[0];
  1423. } else {
  1424. for (i = 0; i < pin->num_ports; i++) {
  1425. pin->mst_capable = true;
  1426. if (pin->ports[i].id == pipe) {
  1427. hport = &pin->ports[i];
  1428. break;
  1429. }
  1430. }
  1431. }
  1432. if (hport)
  1433. hdac_hdmi_present_sense(pin, hport);
  1434. }
  1435. }
  1436. static struct drm_audio_component_audio_ops aops = {
  1437. .pin2port = hdac_hdmi_pin2port,
  1438. .pin_eld_notify = hdac_hdmi_eld_notify_cb,
  1439. };
  1440. static struct snd_pcm *hdac_hdmi_get_pcm_from_id(struct snd_soc_card *card,
  1441. int device)
  1442. {
  1443. struct snd_soc_pcm_runtime *rtd;
  1444. for_each_card_rtds(card, rtd) {
  1445. if (rtd->pcm && (rtd->pcm->device == device))
  1446. return rtd->pcm;
  1447. }
  1448. return NULL;
  1449. }
  1450. /* create jack pin kcontrols */
  1451. static int create_fill_jack_kcontrols(struct snd_soc_card *card,
  1452. struct hdac_device *hdev)
  1453. {
  1454. struct hdac_hdmi_pin *pin;
  1455. struct snd_kcontrol_new *kc;
  1456. char kc_name[NAME_SIZE], xname[NAME_SIZE];
  1457. char *name;
  1458. int i = 0, j;
  1459. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  1460. struct snd_soc_component *component = hdmi->component;
  1461. kc = devm_kcalloc(component->dev, hdmi->num_ports,
  1462. sizeof(*kc), GFP_KERNEL);
  1463. if (!kc)
  1464. return -ENOMEM;
  1465. list_for_each_entry(pin, &hdmi->pin_list, head) {
  1466. for (j = 0; j < pin->num_ports; j++) {
  1467. snprintf(xname, sizeof(xname), "hif%d-%d Jack",
  1468. pin->nid, pin->ports[j].id);
  1469. name = devm_kstrdup(component->dev, xname, GFP_KERNEL);
  1470. if (!name)
  1471. return -ENOMEM;
  1472. snprintf(kc_name, sizeof(kc_name), "%s Switch", xname);
  1473. kc[i].name = devm_kstrdup(component->dev, kc_name,
  1474. GFP_KERNEL);
  1475. if (!kc[i].name)
  1476. return -ENOMEM;
  1477. kc[i].private_value = (unsigned long)name;
  1478. kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  1479. kc[i].access = 0;
  1480. kc[i].info = snd_soc_dapm_info_pin_switch;
  1481. kc[i].put = snd_soc_dapm_put_pin_switch;
  1482. kc[i].get = snd_soc_dapm_get_pin_switch;
  1483. i++;
  1484. }
  1485. }
  1486. return snd_soc_add_card_controls(card, kc, i);
  1487. }
  1488. int hdac_hdmi_jack_port_init(struct snd_soc_component *component,
  1489. struct snd_soc_dapm_context *dapm)
  1490. {
  1491. struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
  1492. struct hdac_device *hdev = hdmi->hdev;
  1493. struct hdac_hdmi_pin *pin;
  1494. struct snd_soc_dapm_widget *widgets;
  1495. struct snd_soc_dapm_route *route;
  1496. char w_name[NAME_SIZE];
  1497. int i = 0, j, ret;
  1498. widgets = devm_kcalloc(dapm->dev, hdmi->num_ports,
  1499. sizeof(*widgets), GFP_KERNEL);
  1500. if (!widgets)
  1501. return -ENOMEM;
  1502. route = devm_kcalloc(dapm->dev, hdmi->num_ports,
  1503. sizeof(*route), GFP_KERNEL);
  1504. if (!route)
  1505. return -ENOMEM;
  1506. /* create Jack DAPM widget */
  1507. list_for_each_entry(pin, &hdmi->pin_list, head) {
  1508. for (j = 0; j < pin->num_ports; j++) {
  1509. snprintf(w_name, sizeof(w_name), "hif%d-%d Jack",
  1510. pin->nid, pin->ports[j].id);
  1511. ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
  1512. snd_soc_dapm_spk, NULL,
  1513. w_name, NULL, NULL, 0, NULL, 0);
  1514. if (ret < 0)
  1515. return ret;
  1516. pin->ports[j].jack_pin = widgets[i].name;
  1517. pin->ports[j].dapm = dapm;
  1518. /* add to route from Jack widget to output */
  1519. hdac_hdmi_fill_route(&route[i], pin->ports[j].jack_pin,
  1520. NULL, pin->ports[j].output_pin, NULL);
  1521. i++;
  1522. }
  1523. }
  1524. /* Add Route from Jack widget to the output widget */
  1525. ret = snd_soc_dapm_new_controls(dapm, widgets, hdmi->num_ports);
  1526. if (ret < 0)
  1527. return ret;
  1528. ret = snd_soc_dapm_add_routes(dapm, route, hdmi->num_ports);
  1529. if (ret < 0)
  1530. return ret;
  1531. ret = snd_soc_dapm_new_widgets(dapm->card);
  1532. if (ret < 0)
  1533. return ret;
  1534. /* Add Jack Pin switch Kcontrol */
  1535. ret = create_fill_jack_kcontrols(dapm->card, hdev);
  1536. if (ret < 0)
  1537. return ret;
  1538. /* default set the Jack Pin switch to OFF */
  1539. list_for_each_entry(pin, &hdmi->pin_list, head) {
  1540. for (j = 0; j < pin->num_ports; j++)
  1541. snd_soc_dapm_disable_pin(pin->ports[j].dapm,
  1542. pin->ports[j].jack_pin);
  1543. }
  1544. return 0;
  1545. }
  1546. EXPORT_SYMBOL_GPL(hdac_hdmi_jack_port_init);
  1547. int hdac_hdmi_jack_init(struct snd_soc_dai *dai, int device,
  1548. struct snd_soc_jack *jack)
  1549. {
  1550. struct snd_soc_component *component = dai->component;
  1551. struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
  1552. struct hdac_device *hdev = hdmi->hdev;
  1553. struct hdac_hdmi_pcm *pcm;
  1554. struct snd_pcm *snd_pcm;
  1555. int err;
  1556. /*
  1557. * this is a new PCM device, create new pcm and
  1558. * add to the pcm list
  1559. */
  1560. pcm = devm_kzalloc(&hdev->dev, sizeof(*pcm), GFP_KERNEL);
  1561. if (!pcm)
  1562. return -ENOMEM;
  1563. pcm->pcm_id = device;
  1564. pcm->cvt = hdmi->dai_map[dai->id].cvt;
  1565. pcm->jack_event = 0;
  1566. pcm->jack = jack;
  1567. mutex_init(&pcm->lock);
  1568. INIT_LIST_HEAD(&pcm->port_list);
  1569. snd_pcm = hdac_hdmi_get_pcm_from_id(dai->component->card, device);
  1570. if (snd_pcm) {
  1571. err = snd_hdac_add_chmap_ctls(snd_pcm, device, &hdmi->chmap);
  1572. if (err < 0) {
  1573. dev_err(&hdev->dev,
  1574. "chmap control add failed with err: %d for pcm: %d\n",
  1575. err, device);
  1576. return err;
  1577. }
  1578. }
  1579. /* add control for ELD Bytes */
  1580. err = hdac_hdmi_create_eld_ctl(component, pcm);
  1581. if (err < 0) {
  1582. dev_err(&hdev->dev,
  1583. "eld control add failed with err: %d for pcm: %d\n",
  1584. err, device);
  1585. return err;
  1586. }
  1587. list_add_tail(&pcm->head, &hdmi->pcm_list);
  1588. return 0;
  1589. }
  1590. EXPORT_SYMBOL_GPL(hdac_hdmi_jack_init);
  1591. static void hdac_hdmi_present_sense_all_pins(struct hdac_device *hdev,
  1592. struct hdac_hdmi_priv *hdmi, bool detect_pin_caps)
  1593. {
  1594. int i;
  1595. struct hdac_hdmi_pin *pin;
  1596. list_for_each_entry(pin, &hdmi->pin_list, head) {
  1597. if (detect_pin_caps) {
  1598. if (hdac_hdmi_get_port_len(hdev, pin->nid) == 0)
  1599. pin->mst_capable = false;
  1600. else
  1601. pin->mst_capable = true;
  1602. }
  1603. for (i = 0; i < pin->num_ports; i++) {
  1604. if (!pin->mst_capable && i > 0)
  1605. continue;
  1606. hdac_hdmi_present_sense(pin, &pin->ports[i]);
  1607. }
  1608. }
  1609. }
  1610. static int hdmi_codec_probe(struct snd_soc_component *component)
  1611. {
  1612. struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
  1613. struct hdac_device *hdev = hdmi->hdev;
  1614. struct snd_soc_dapm_context *dapm =
  1615. snd_soc_component_get_dapm(component);
  1616. struct hdac_ext_link *hlink;
  1617. int ret;
  1618. hdmi->component = component;
  1619. /*
  1620. * hold the ref while we probe, also no need to drop the ref on
  1621. * exit, we call pm_runtime_suspend() so that will do for us
  1622. */
  1623. hlink = snd_hdac_ext_bus_get_link(hdev->bus, dev_name(&hdev->dev));
  1624. if (!hlink) {
  1625. dev_err(&hdev->dev, "hdac link not found\n");
  1626. return -EIO;
  1627. }
  1628. snd_hdac_ext_bus_link_get(hdev->bus, hlink);
  1629. ret = create_fill_widget_route_map(dapm);
  1630. if (ret < 0)
  1631. return ret;
  1632. aops.audio_ptr = hdev;
  1633. ret = snd_hdac_acomp_register_notifier(hdev->bus, &aops);
  1634. if (ret < 0) {
  1635. dev_err(&hdev->dev, "notifier register failed: err: %d\n", ret);
  1636. return ret;
  1637. }
  1638. hdac_hdmi_present_sense_all_pins(hdev, hdmi, true);
  1639. /* Imp: Store the card pointer in hda_codec */
  1640. hdmi->card = dapm->card->snd_card;
  1641. /*
  1642. * Setup a device_link between card device and HDMI codec device.
  1643. * The card device is the consumer and the HDMI codec device is
  1644. * the supplier. With this setting, we can make sure that the audio
  1645. * domain in display power will be always turned on before operating
  1646. * on the HDMI audio codec registers.
  1647. * Let's use the flag DL_FLAG_AUTOREMOVE_CONSUMER. This can make
  1648. * sure the device link is freed when the machine driver is removed.
  1649. */
  1650. device_link_add(component->card->dev, &hdev->dev, DL_FLAG_RPM_ACTIVE |
  1651. DL_FLAG_AUTOREMOVE_CONSUMER);
  1652. /*
  1653. * hdac_device core already sets the state to active and calls
  1654. * get_noresume. So enable runtime and set the device to suspend.
  1655. */
  1656. pm_runtime_enable(&hdev->dev);
  1657. pm_runtime_put(&hdev->dev);
  1658. pm_runtime_suspend(&hdev->dev);
  1659. return 0;
  1660. }
  1661. static void hdmi_codec_remove(struct snd_soc_component *component)
  1662. {
  1663. struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
  1664. struct hdac_device *hdev = hdmi->hdev;
  1665. int ret;
  1666. ret = snd_hdac_acomp_register_notifier(hdev->bus, NULL);
  1667. if (ret < 0)
  1668. dev_err(&hdev->dev, "notifier unregister failed: err: %d\n",
  1669. ret);
  1670. pm_runtime_disable(&hdev->dev);
  1671. }
  1672. #ifdef CONFIG_PM_SLEEP
  1673. static int hdmi_codec_resume(struct device *dev)
  1674. {
  1675. struct hdac_device *hdev = dev_to_hdac_dev(dev);
  1676. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  1677. int ret;
  1678. ret = pm_runtime_force_resume(dev);
  1679. if (ret < 0)
  1680. return ret;
  1681. /*
  1682. * As the ELD notify callback request is not entertained while the
  1683. * device is in suspend state. Need to manually check detection of
  1684. * all pins here. pin capablity change is not support, so use the
  1685. * already set pin caps.
  1686. *
  1687. * NOTE: this is safe to call even if the codec doesn't actually resume.
  1688. * The pin check involves only with DRM audio component hooks, so it
  1689. * works even if the HD-audio side is still dreaming peacefully.
  1690. */
  1691. hdac_hdmi_present_sense_all_pins(hdev, hdmi, false);
  1692. return 0;
  1693. }
  1694. #else
  1695. #define hdmi_codec_resume NULL
  1696. #endif
  1697. static const struct snd_soc_component_driver hdmi_hda_codec = {
  1698. .probe = hdmi_codec_probe,
  1699. .remove = hdmi_codec_remove,
  1700. .use_pmdown_time = 1,
  1701. .endianness = 1,
  1702. };
  1703. static void hdac_hdmi_get_chmap(struct hdac_device *hdev, int pcm_idx,
  1704. unsigned char *chmap)
  1705. {
  1706. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  1707. struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
  1708. memcpy(chmap, pcm->chmap, ARRAY_SIZE(pcm->chmap));
  1709. }
  1710. static void hdac_hdmi_set_chmap(struct hdac_device *hdev, int pcm_idx,
  1711. unsigned char *chmap, int prepared)
  1712. {
  1713. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  1714. struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
  1715. struct hdac_hdmi_port *port;
  1716. if (!pcm)
  1717. return;
  1718. if (list_empty(&pcm->port_list))
  1719. return;
  1720. mutex_lock(&pcm->lock);
  1721. pcm->chmap_set = true;
  1722. memcpy(pcm->chmap, chmap, ARRAY_SIZE(pcm->chmap));
  1723. list_for_each_entry(port, &pcm->port_list, head)
  1724. if (prepared)
  1725. hdac_hdmi_setup_audio_infoframe(hdev, pcm, port);
  1726. mutex_unlock(&pcm->lock);
  1727. }
  1728. static bool is_hdac_hdmi_pcm_attached(struct hdac_device *hdev, int pcm_idx)
  1729. {
  1730. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  1731. struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
  1732. if (!pcm)
  1733. return false;
  1734. if (list_empty(&pcm->port_list))
  1735. return false;
  1736. return true;
  1737. }
  1738. static int hdac_hdmi_get_spk_alloc(struct hdac_device *hdev, int pcm_idx)
  1739. {
  1740. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  1741. struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
  1742. struct hdac_hdmi_port *port;
  1743. if (!pcm)
  1744. return 0;
  1745. if (list_empty(&pcm->port_list))
  1746. return 0;
  1747. port = list_first_entry(&pcm->port_list, struct hdac_hdmi_port, head);
  1748. if (!port || !port->eld.eld_valid)
  1749. return 0;
  1750. return port->eld.info.spk_alloc;
  1751. }
  1752. static struct hdac_hdmi_drv_data intel_glk_drv_data = {
  1753. .vendor_nid = INTEL_GLK_VENDOR_NID,
  1754. };
  1755. static struct hdac_hdmi_drv_data intel_drv_data = {
  1756. .vendor_nid = INTEL_VENDOR_NID,
  1757. };
  1758. static int hdac_hdmi_dev_probe(struct hdac_device *hdev)
  1759. {
  1760. struct hdac_hdmi_priv *hdmi_priv;
  1761. struct snd_soc_dai_driver *hdmi_dais = NULL;
  1762. struct hdac_ext_link *hlink;
  1763. int num_dais = 0;
  1764. int ret;
  1765. struct hdac_driver *hdrv = drv_to_hdac_driver(hdev->dev.driver);
  1766. const struct hda_device_id *hdac_id = hdac_get_device_id(hdev, hdrv);
  1767. /* hold the ref while we probe */
  1768. hlink = snd_hdac_ext_bus_get_link(hdev->bus, dev_name(&hdev->dev));
  1769. if (!hlink) {
  1770. dev_err(&hdev->dev, "hdac link not found\n");
  1771. return -EIO;
  1772. }
  1773. snd_hdac_ext_bus_link_get(hdev->bus, hlink);
  1774. hdmi_priv = devm_kzalloc(&hdev->dev, sizeof(*hdmi_priv), GFP_KERNEL);
  1775. if (hdmi_priv == NULL)
  1776. return -ENOMEM;
  1777. snd_hdac_register_chmap_ops(hdev, &hdmi_priv->chmap);
  1778. hdmi_priv->chmap.ops.get_chmap = hdac_hdmi_get_chmap;
  1779. hdmi_priv->chmap.ops.set_chmap = hdac_hdmi_set_chmap;
  1780. hdmi_priv->chmap.ops.is_pcm_attached = is_hdac_hdmi_pcm_attached;
  1781. hdmi_priv->chmap.ops.get_spk_alloc = hdac_hdmi_get_spk_alloc;
  1782. hdmi_priv->hdev = hdev;
  1783. if (!hdac_id)
  1784. return -ENODEV;
  1785. if (hdac_id->driver_data)
  1786. hdmi_priv->drv_data =
  1787. (struct hdac_hdmi_drv_data *)hdac_id->driver_data;
  1788. else
  1789. hdmi_priv->drv_data = &intel_drv_data;
  1790. dev_set_drvdata(&hdev->dev, hdmi_priv);
  1791. INIT_LIST_HEAD(&hdmi_priv->pin_list);
  1792. INIT_LIST_HEAD(&hdmi_priv->cvt_list);
  1793. INIT_LIST_HEAD(&hdmi_priv->pcm_list);
  1794. mutex_init(&hdmi_priv->pin_mutex);
  1795. /*
  1796. * Turned off in the runtime_suspend during the first explicit
  1797. * pm_runtime_suspend call.
  1798. */
  1799. snd_hdac_display_power(hdev->bus, hdev->addr, true);
  1800. ret = hdac_hdmi_parse_and_map_nid(hdev, &hdmi_dais, &num_dais);
  1801. if (ret < 0) {
  1802. dev_err(&hdev->dev,
  1803. "Failed in parse and map nid with err: %d\n", ret);
  1804. return ret;
  1805. }
  1806. snd_hdac_refresh_widgets(hdev);
  1807. /* ASoC specific initialization */
  1808. ret = devm_snd_soc_register_component(&hdev->dev, &hdmi_hda_codec,
  1809. hdmi_dais, num_dais);
  1810. snd_hdac_ext_bus_link_put(hdev->bus, hlink);
  1811. return ret;
  1812. }
  1813. static void clear_dapm_works(struct hdac_device *hdev)
  1814. {
  1815. struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
  1816. struct hdac_hdmi_pin *pin;
  1817. int i;
  1818. list_for_each_entry(pin, &hdmi->pin_list, head)
  1819. for (i = 0; i < pin->num_ports; i++)
  1820. cancel_work_sync(&pin->ports[i].dapm_work);
  1821. }
  1822. static int hdac_hdmi_dev_remove(struct hdac_device *hdev)
  1823. {
  1824. clear_dapm_works(hdev);
  1825. snd_hdac_display_power(hdev->bus, hdev->addr, false);
  1826. return 0;
  1827. }
  1828. #ifdef CONFIG_PM
  1829. static int hdac_hdmi_runtime_suspend(struct device *dev)
  1830. {
  1831. struct hdac_device *hdev = dev_to_hdac_dev(dev);
  1832. struct hdac_bus *bus = hdev->bus;
  1833. struct hdac_ext_link *hlink;
  1834. dev_dbg(dev, "Enter: %s\n", __func__);
  1835. /* controller may not have been initialized for the first time */
  1836. if (!bus)
  1837. return 0;
  1838. /*
  1839. * Power down afg.
  1840. * codec_read is preferred over codec_write to set the power state.
  1841. * This way verb is send to set the power state and response
  1842. * is received. So setting power state is ensured without using loop
  1843. * to read the state.
  1844. */
  1845. snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
  1846. AC_PWRST_D3);
  1847. hlink = snd_hdac_ext_bus_get_link(bus, dev_name(dev));
  1848. if (!hlink) {
  1849. dev_err(dev, "hdac link not found\n");
  1850. return -EIO;
  1851. }
  1852. snd_hdac_codec_link_down(hdev);
  1853. snd_hdac_ext_bus_link_put(bus, hlink);
  1854. snd_hdac_display_power(bus, hdev->addr, false);
  1855. return 0;
  1856. }
  1857. static int hdac_hdmi_runtime_resume(struct device *dev)
  1858. {
  1859. struct hdac_device *hdev = dev_to_hdac_dev(dev);
  1860. struct hdac_bus *bus = hdev->bus;
  1861. struct hdac_ext_link *hlink;
  1862. dev_dbg(dev, "Enter: %s\n", __func__);
  1863. /* controller may not have been initialized for the first time */
  1864. if (!bus)
  1865. return 0;
  1866. hlink = snd_hdac_ext_bus_get_link(bus, dev_name(dev));
  1867. if (!hlink) {
  1868. dev_err(dev, "hdac link not found\n");
  1869. return -EIO;
  1870. }
  1871. snd_hdac_ext_bus_link_get(bus, hlink);
  1872. snd_hdac_codec_link_up(hdev);
  1873. snd_hdac_display_power(bus, hdev->addr, true);
  1874. hdac_hdmi_skl_enable_all_pins(hdev);
  1875. hdac_hdmi_skl_enable_dp12(hdev);
  1876. /* Power up afg */
  1877. snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
  1878. AC_PWRST_D0);
  1879. return 0;
  1880. }
  1881. #else
  1882. #define hdac_hdmi_runtime_suspend NULL
  1883. #define hdac_hdmi_runtime_resume NULL
  1884. #endif
  1885. static const struct dev_pm_ops hdac_hdmi_pm = {
  1886. SET_RUNTIME_PM_OPS(hdac_hdmi_runtime_suspend, hdac_hdmi_runtime_resume, NULL)
  1887. SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, hdmi_codec_resume)
  1888. };
  1889. static const struct hda_device_id hdmi_list[] = {
  1890. HDA_CODEC_EXT_ENTRY(0x80862809, 0x100000, "Skylake HDMI", 0),
  1891. HDA_CODEC_EXT_ENTRY(0x8086280a, 0x100000, "Broxton HDMI", 0),
  1892. HDA_CODEC_EXT_ENTRY(0x8086280b, 0x100000, "Kabylake HDMI", 0),
  1893. HDA_CODEC_EXT_ENTRY(0x8086280c, 0x100000, "Cannonlake HDMI",
  1894. &intel_glk_drv_data),
  1895. HDA_CODEC_EXT_ENTRY(0x8086280d, 0x100000, "Geminilake HDMI",
  1896. &intel_glk_drv_data),
  1897. {}
  1898. };
  1899. MODULE_DEVICE_TABLE(hdaudio, hdmi_list);
  1900. static struct hdac_driver hdmi_driver = {
  1901. .driver = {
  1902. .name = "HDMI HDA Codec",
  1903. .pm = &hdac_hdmi_pm,
  1904. },
  1905. .id_table = hdmi_list,
  1906. .probe = hdac_hdmi_dev_probe,
  1907. .remove = hdac_hdmi_dev_remove,
  1908. };
  1909. static int __init hdmi_init(void)
  1910. {
  1911. return snd_hda_ext_driver_register(&hdmi_driver);
  1912. }
  1913. static void __exit hdmi_exit(void)
  1914. {
  1915. snd_hda_ext_driver_unregister(&hdmi_driver);
  1916. }
  1917. module_init(hdmi_init);
  1918. module_exit(hdmi_exit);
  1919. MODULE_LICENSE("GPL v2");
  1920. MODULE_DESCRIPTION("HDMI HD codec");
  1921. MODULE_AUTHOR("Samreen Nilofer<[email protected]>");
  1922. MODULE_AUTHOR("Subhransu S. Prusty<[email protected]>");