hdac_hda.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright(c) 2015-18 Intel Corporation.
  3. /*
  4. * hdac_hda.c - ASoC extensions to reuse the legacy HDA codec drivers
  5. * with ASoC platform drivers. These APIs are called by the legacy HDA
  6. * codec drivers using hdac_ext_bus_ops ops.
  7. */
  8. #include <linux/init.h>
  9. #include <linux/delay.h>
  10. #include <linux/module.h>
  11. #include <linux/pm_runtime.h>
  12. #include <sound/pcm_params.h>
  13. #include <sound/soc.h>
  14. #include <sound/hdaudio_ext.h>
  15. #include <sound/hda_i915.h>
  16. #include <sound/hda_codec.h>
  17. #include <sound/hda_register.h>
  18. #include "hdac_hda.h"
  19. #define STUB_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
  20. SNDRV_PCM_FMTBIT_U8 | \
  21. SNDRV_PCM_FMTBIT_S16_LE | \
  22. SNDRV_PCM_FMTBIT_U16_LE | \
  23. SNDRV_PCM_FMTBIT_S24_LE | \
  24. SNDRV_PCM_FMTBIT_U24_LE | \
  25. SNDRV_PCM_FMTBIT_S32_LE | \
  26. SNDRV_PCM_FMTBIT_U32_LE | \
  27. SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE)
  28. #define STUB_HDMI_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
  29. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\
  30. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
  31. SNDRV_PCM_RATE_192000)
  32. static int hdac_hda_dai_open(struct snd_pcm_substream *substream,
  33. struct snd_soc_dai *dai);
  34. static void hdac_hda_dai_close(struct snd_pcm_substream *substream,
  35. struct snd_soc_dai *dai);
  36. static int hdac_hda_dai_prepare(struct snd_pcm_substream *substream,
  37. struct snd_soc_dai *dai);
  38. static int hdac_hda_dai_hw_params(struct snd_pcm_substream *substream,
  39. struct snd_pcm_hw_params *params,
  40. struct snd_soc_dai *dai);
  41. static int hdac_hda_dai_hw_free(struct snd_pcm_substream *substream,
  42. struct snd_soc_dai *dai);
  43. static int hdac_hda_dai_set_stream(struct snd_soc_dai *dai, void *stream,
  44. int direction);
  45. static struct hda_pcm *snd_soc_find_pcm_from_dai(struct hdac_hda_priv *hda_pvt,
  46. struct snd_soc_dai *dai);
  47. static const struct snd_soc_dai_ops hdac_hda_dai_ops = {
  48. .startup = hdac_hda_dai_open,
  49. .shutdown = hdac_hda_dai_close,
  50. .prepare = hdac_hda_dai_prepare,
  51. .hw_params = hdac_hda_dai_hw_params,
  52. .hw_free = hdac_hda_dai_hw_free,
  53. .set_stream = hdac_hda_dai_set_stream,
  54. };
  55. static struct snd_soc_dai_driver hdac_hda_dais[] = {
  56. {
  57. .id = HDAC_ANALOG_DAI_ID,
  58. .name = "Analog Codec DAI",
  59. .ops = &hdac_hda_dai_ops,
  60. .playback = {
  61. .stream_name = "Analog Codec Playback",
  62. .channels_min = 1,
  63. .channels_max = 16,
  64. .rates = SNDRV_PCM_RATE_8000_192000,
  65. .formats = STUB_FORMATS,
  66. .sig_bits = 24,
  67. },
  68. .capture = {
  69. .stream_name = "Analog Codec Capture",
  70. .channels_min = 1,
  71. .channels_max = 16,
  72. .rates = SNDRV_PCM_RATE_8000_192000,
  73. .formats = STUB_FORMATS,
  74. .sig_bits = 24,
  75. },
  76. },
  77. {
  78. .id = HDAC_DIGITAL_DAI_ID,
  79. .name = "Digital Codec DAI",
  80. .ops = &hdac_hda_dai_ops,
  81. .playback = {
  82. .stream_name = "Digital Codec Playback",
  83. .channels_min = 1,
  84. .channels_max = 16,
  85. .rates = SNDRV_PCM_RATE_8000_192000,
  86. .formats = STUB_FORMATS,
  87. .sig_bits = 24,
  88. },
  89. .capture = {
  90. .stream_name = "Digital Codec Capture",
  91. .channels_min = 1,
  92. .channels_max = 16,
  93. .rates = SNDRV_PCM_RATE_8000_192000,
  94. .formats = STUB_FORMATS,
  95. .sig_bits = 24,
  96. },
  97. },
  98. {
  99. .id = HDAC_ALT_ANALOG_DAI_ID,
  100. .name = "Alt Analog Codec DAI",
  101. .ops = &hdac_hda_dai_ops,
  102. .playback = {
  103. .stream_name = "Alt Analog Codec Playback",
  104. .channels_min = 1,
  105. .channels_max = 16,
  106. .rates = SNDRV_PCM_RATE_8000_192000,
  107. .formats = STUB_FORMATS,
  108. .sig_bits = 24,
  109. },
  110. .capture = {
  111. .stream_name = "Alt Analog Codec Capture",
  112. .channels_min = 1,
  113. .channels_max = 16,
  114. .rates = SNDRV_PCM_RATE_8000_192000,
  115. .formats = STUB_FORMATS,
  116. .sig_bits = 24,
  117. },
  118. },
  119. {
  120. .id = HDAC_HDMI_0_DAI_ID,
  121. .name = "intel-hdmi-hifi1",
  122. .ops = &hdac_hda_dai_ops,
  123. .playback = {
  124. .stream_name = "hifi1",
  125. .channels_min = 1,
  126. .channels_max = 32,
  127. .rates = STUB_HDMI_RATES,
  128. .formats = STUB_FORMATS,
  129. .sig_bits = 24,
  130. },
  131. },
  132. {
  133. .id = HDAC_HDMI_1_DAI_ID,
  134. .name = "intel-hdmi-hifi2",
  135. .ops = &hdac_hda_dai_ops,
  136. .playback = {
  137. .stream_name = "hifi2",
  138. .channels_min = 1,
  139. .channels_max = 32,
  140. .rates = STUB_HDMI_RATES,
  141. .formats = STUB_FORMATS,
  142. .sig_bits = 24,
  143. },
  144. },
  145. {
  146. .id = HDAC_HDMI_2_DAI_ID,
  147. .name = "intel-hdmi-hifi3",
  148. .ops = &hdac_hda_dai_ops,
  149. .playback = {
  150. .stream_name = "hifi3",
  151. .channels_min = 1,
  152. .channels_max = 32,
  153. .rates = STUB_HDMI_RATES,
  154. .formats = STUB_FORMATS,
  155. .sig_bits = 24,
  156. },
  157. },
  158. {
  159. .id = HDAC_HDMI_3_DAI_ID,
  160. .name = "intel-hdmi-hifi4",
  161. .ops = &hdac_hda_dai_ops,
  162. .playback = {
  163. .stream_name = "hifi4",
  164. .channels_min = 1,
  165. .channels_max = 32,
  166. .rates = STUB_HDMI_RATES,
  167. .formats = STUB_FORMATS,
  168. .sig_bits = 24,
  169. },
  170. },
  171. };
  172. static int hdac_hda_dai_set_stream(struct snd_soc_dai *dai,
  173. void *stream, int direction)
  174. {
  175. struct snd_soc_component *component = dai->component;
  176. struct hdac_hda_priv *hda_pvt;
  177. struct hdac_hda_pcm *pcm;
  178. struct hdac_stream *hstream;
  179. if (!stream)
  180. return -EINVAL;
  181. hda_pvt = snd_soc_component_get_drvdata(component);
  182. pcm = &hda_pvt->pcm[dai->id];
  183. hstream = (struct hdac_stream *)stream;
  184. pcm->stream_tag[direction] = hstream->stream_tag;
  185. return 0;
  186. }
  187. static int hdac_hda_dai_hw_params(struct snd_pcm_substream *substream,
  188. struct snd_pcm_hw_params *params,
  189. struct snd_soc_dai *dai)
  190. {
  191. struct snd_soc_component *component = dai->component;
  192. struct hdac_hda_priv *hda_pvt;
  193. unsigned int format_val;
  194. unsigned int maxbps;
  195. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  196. maxbps = dai->driver->playback.sig_bits;
  197. else
  198. maxbps = dai->driver->capture.sig_bits;
  199. hda_pvt = snd_soc_component_get_drvdata(component);
  200. format_val = snd_hdac_calc_stream_format(params_rate(params),
  201. params_channels(params),
  202. params_format(params),
  203. maxbps,
  204. 0);
  205. if (!format_val) {
  206. dev_err(dai->dev,
  207. "invalid format_val, rate=%d, ch=%d, format=%d, maxbps=%d\n",
  208. params_rate(params), params_channels(params),
  209. params_format(params), maxbps);
  210. return -EINVAL;
  211. }
  212. hda_pvt->pcm[dai->id].format_val[substream->stream] = format_val;
  213. return 0;
  214. }
  215. static int hdac_hda_dai_hw_free(struct snd_pcm_substream *substream,
  216. struct snd_soc_dai *dai)
  217. {
  218. struct snd_soc_component *component = dai->component;
  219. struct hdac_hda_priv *hda_pvt;
  220. struct hda_pcm_stream *hda_stream;
  221. struct hda_pcm *pcm;
  222. hda_pvt = snd_soc_component_get_drvdata(component);
  223. pcm = snd_soc_find_pcm_from_dai(hda_pvt, dai);
  224. if (!pcm)
  225. return -EINVAL;
  226. hda_stream = &pcm->stream[substream->stream];
  227. snd_hda_codec_cleanup(hda_pvt->codec, hda_stream, substream);
  228. return 0;
  229. }
  230. static int hdac_hda_dai_prepare(struct snd_pcm_substream *substream,
  231. struct snd_soc_dai *dai)
  232. {
  233. struct snd_soc_component *component = dai->component;
  234. struct hda_pcm_stream *hda_stream;
  235. struct hdac_hda_priv *hda_pvt;
  236. struct hdac_device *hdev;
  237. unsigned int format_val;
  238. struct hda_pcm *pcm;
  239. unsigned int stream;
  240. int ret = 0;
  241. hda_pvt = snd_soc_component_get_drvdata(component);
  242. hdev = &hda_pvt->codec->core;
  243. pcm = snd_soc_find_pcm_from_dai(hda_pvt, dai);
  244. if (!pcm)
  245. return -EINVAL;
  246. hda_stream = &pcm->stream[substream->stream];
  247. stream = hda_pvt->pcm[dai->id].stream_tag[substream->stream];
  248. format_val = hda_pvt->pcm[dai->id].format_val[substream->stream];
  249. ret = snd_hda_codec_prepare(hda_pvt->codec, hda_stream,
  250. stream, format_val, substream);
  251. if (ret < 0)
  252. dev_err(&hdev->dev, "codec prepare failed %d\n", ret);
  253. return ret;
  254. }
  255. static int hdac_hda_dai_open(struct snd_pcm_substream *substream,
  256. struct snd_soc_dai *dai)
  257. {
  258. struct snd_soc_component *component = dai->component;
  259. struct hdac_hda_priv *hda_pvt;
  260. struct hda_pcm_stream *hda_stream;
  261. struct hda_pcm *pcm;
  262. hda_pvt = snd_soc_component_get_drvdata(component);
  263. pcm = snd_soc_find_pcm_from_dai(hda_pvt, dai);
  264. if (!pcm)
  265. return -EINVAL;
  266. snd_hda_codec_pcm_get(pcm);
  267. hda_stream = &pcm->stream[substream->stream];
  268. return hda_stream->ops.open(hda_stream, hda_pvt->codec, substream);
  269. }
  270. static void hdac_hda_dai_close(struct snd_pcm_substream *substream,
  271. struct snd_soc_dai *dai)
  272. {
  273. struct snd_soc_component *component = dai->component;
  274. struct hdac_hda_priv *hda_pvt;
  275. struct hda_pcm_stream *hda_stream;
  276. struct hda_pcm *pcm;
  277. hda_pvt = snd_soc_component_get_drvdata(component);
  278. pcm = snd_soc_find_pcm_from_dai(hda_pvt, dai);
  279. if (!pcm)
  280. return;
  281. hda_stream = &pcm->stream[substream->stream];
  282. hda_stream->ops.close(hda_stream, hda_pvt->codec, substream);
  283. snd_hda_codec_pcm_put(pcm);
  284. }
  285. static struct hda_pcm *snd_soc_find_pcm_from_dai(struct hdac_hda_priv *hda_pvt,
  286. struct snd_soc_dai *dai)
  287. {
  288. struct hda_codec *hcodec = hda_pvt->codec;
  289. struct hda_pcm *cpcm;
  290. const char *pcm_name;
  291. /*
  292. * map DAI ID to the closest matching PCM name, using the naming
  293. * scheme used by hda-codec snd_hda_gen_build_pcms() and for
  294. * HDMI in hda_codec patch_hdmi.c)
  295. */
  296. switch (dai->id) {
  297. case HDAC_ANALOG_DAI_ID:
  298. pcm_name = "Analog";
  299. break;
  300. case HDAC_DIGITAL_DAI_ID:
  301. pcm_name = "Digital";
  302. break;
  303. case HDAC_ALT_ANALOG_DAI_ID:
  304. pcm_name = "Alt Analog";
  305. break;
  306. case HDAC_HDMI_0_DAI_ID:
  307. pcm_name = "HDMI 0";
  308. break;
  309. case HDAC_HDMI_1_DAI_ID:
  310. pcm_name = "HDMI 1";
  311. break;
  312. case HDAC_HDMI_2_DAI_ID:
  313. pcm_name = "HDMI 2";
  314. break;
  315. case HDAC_HDMI_3_DAI_ID:
  316. pcm_name = "HDMI 3";
  317. break;
  318. default:
  319. dev_err(&hcodec->core.dev, "invalid dai id %d\n", dai->id);
  320. return NULL;
  321. }
  322. list_for_each_entry(cpcm, &hcodec->pcm_list_head, list) {
  323. if (strstr(cpcm->name, pcm_name)) {
  324. if (strcmp(pcm_name, "Analog") == 0) {
  325. if (strstr(cpcm->name, "Alt Analog"))
  326. continue;
  327. }
  328. return cpcm;
  329. }
  330. }
  331. dev_err(&hcodec->core.dev, "didn't find PCM for DAI %s\n", dai->name);
  332. return NULL;
  333. }
  334. static bool is_hdmi_codec(struct hda_codec *hcodec)
  335. {
  336. struct hda_pcm *cpcm;
  337. list_for_each_entry(cpcm, &hcodec->pcm_list_head, list) {
  338. if (cpcm->pcm_type == HDA_PCM_TYPE_HDMI)
  339. return true;
  340. }
  341. return false;
  342. }
  343. static int hdac_hda_codec_probe(struct snd_soc_component *component)
  344. {
  345. struct hdac_hda_priv *hda_pvt =
  346. snd_soc_component_get_drvdata(component);
  347. struct snd_soc_dapm_context *dapm =
  348. snd_soc_component_get_dapm(component);
  349. struct hdac_device *hdev = &hda_pvt->codec->core;
  350. struct hda_codec *hcodec = hda_pvt->codec;
  351. struct hdac_ext_link *hlink;
  352. hda_codec_patch_t patch;
  353. int ret;
  354. hlink = snd_hdac_ext_bus_get_link(hdev->bus, dev_name(&hdev->dev));
  355. if (!hlink) {
  356. dev_err(&hdev->dev, "hdac link not found\n");
  357. return -EIO;
  358. }
  359. snd_hdac_ext_bus_link_get(hdev->bus, hlink);
  360. /*
  361. * Ensure any HDA display is powered at codec probe.
  362. * After snd_hda_codec_device_new(), display power is
  363. * managed by runtime PM.
  364. */
  365. if (hda_pvt->need_display_power)
  366. snd_hdac_display_power(hdev->bus,
  367. HDA_CODEC_IDX_CONTROLLER, true);
  368. ret = snd_hda_codec_device_new(hcodec->bus, component->card->snd_card,
  369. hdev->addr, hcodec, true);
  370. if (ret < 0) {
  371. dev_err(&hdev->dev, "failed to create hda codec %d\n", ret);
  372. goto error_no_pm;
  373. }
  374. /*
  375. * Overwrite type to HDA_DEV_ASOC since it is a ASoC driver
  376. * hda_codec.c will check this flag to determine if unregister
  377. * device is needed.
  378. */
  379. hdev->type = HDA_DEV_ASOC;
  380. /*
  381. * snd_hda_codec_device_new decrements the usage count so call get pm
  382. * else the device will be powered off
  383. */
  384. pm_runtime_get_noresume(&hdev->dev);
  385. hcodec->bus->card = dapm->card->snd_card;
  386. ret = snd_hda_codec_set_name(hcodec, hcodec->preset->name);
  387. if (ret < 0) {
  388. dev_err(&hdev->dev, "name failed %s\n", hcodec->preset->name);
  389. goto error_pm;
  390. }
  391. ret = snd_hdac_regmap_init(&hcodec->core);
  392. if (ret < 0) {
  393. dev_err(&hdev->dev, "regmap init failed\n");
  394. goto error_pm;
  395. }
  396. patch = (hda_codec_patch_t)hcodec->preset->driver_data;
  397. if (patch) {
  398. ret = patch(hcodec);
  399. if (ret < 0) {
  400. dev_err(&hdev->dev, "patch failed %d\n", ret);
  401. goto error_regmap;
  402. }
  403. } else {
  404. dev_dbg(&hdev->dev, "no patch file found\n");
  405. }
  406. ret = snd_hda_codec_parse_pcms(hcodec);
  407. if (ret < 0) {
  408. dev_err(&hdev->dev, "unable to map pcms to dai %d\n", ret);
  409. goto error_patch;
  410. }
  411. /* HDMI controls need to be created in machine drivers */
  412. if (!is_hdmi_codec(hcodec)) {
  413. ret = snd_hda_codec_build_controls(hcodec);
  414. if (ret < 0) {
  415. dev_err(&hdev->dev, "unable to create controls %d\n",
  416. ret);
  417. goto error_patch;
  418. }
  419. }
  420. hcodec->core.lazy_cache = true;
  421. if (hda_pvt->need_display_power)
  422. snd_hdac_display_power(hdev->bus,
  423. HDA_CODEC_IDX_CONTROLLER, false);
  424. /* match for forbid call in snd_hda_codec_device_new() */
  425. pm_runtime_allow(&hdev->dev);
  426. /*
  427. * hdac_device core already sets the state to active and calls
  428. * get_noresume. So enable runtime and set the device to suspend.
  429. * pm_runtime_enable is also called during codec registeration
  430. */
  431. pm_runtime_put(&hdev->dev);
  432. pm_runtime_suspend(&hdev->dev);
  433. return 0;
  434. error_patch:
  435. if (hcodec->patch_ops.free)
  436. hcodec->patch_ops.free(hcodec);
  437. error_regmap:
  438. snd_hdac_regmap_exit(hdev);
  439. error_pm:
  440. pm_runtime_put(&hdev->dev);
  441. error_no_pm:
  442. snd_hdac_ext_bus_link_put(hdev->bus, hlink);
  443. return ret;
  444. }
  445. static void hdac_hda_codec_remove(struct snd_soc_component *component)
  446. {
  447. struct hdac_hda_priv *hda_pvt =
  448. snd_soc_component_get_drvdata(component);
  449. struct hdac_device *hdev = &hda_pvt->codec->core;
  450. struct hda_codec *codec = hda_pvt->codec;
  451. struct hdac_ext_link *hlink = NULL;
  452. hlink = snd_hdac_ext_bus_get_link(hdev->bus, dev_name(&hdev->dev));
  453. if (!hlink) {
  454. dev_err(&hdev->dev, "hdac link not found\n");
  455. return;
  456. }
  457. pm_runtime_disable(&hdev->dev);
  458. snd_hdac_ext_bus_link_put(hdev->bus, hlink);
  459. if (codec->patch_ops.free)
  460. codec->patch_ops.free(codec);
  461. snd_hda_codec_cleanup_for_unbind(codec);
  462. }
  463. static const struct snd_soc_dapm_route hdac_hda_dapm_routes[] = {
  464. {"AIF1TX", NULL, "Codec Input Pin1"},
  465. {"AIF2TX", NULL, "Codec Input Pin2"},
  466. {"AIF3TX", NULL, "Codec Input Pin3"},
  467. {"Codec Output Pin1", NULL, "AIF1RX"},
  468. {"Codec Output Pin2", NULL, "AIF2RX"},
  469. {"Codec Output Pin3", NULL, "AIF3RX"},
  470. };
  471. static const struct snd_soc_dapm_widget hdac_hda_dapm_widgets[] = {
  472. /* Audio Interface */
  473. SND_SOC_DAPM_AIF_IN("AIF1RX", "Analog Codec Playback", 0,
  474. SND_SOC_NOPM, 0, 0),
  475. SND_SOC_DAPM_AIF_IN("AIF2RX", "Digital Codec Playback", 0,
  476. SND_SOC_NOPM, 0, 0),
  477. SND_SOC_DAPM_AIF_IN("AIF3RX", "Alt Analog Codec Playback", 0,
  478. SND_SOC_NOPM, 0, 0),
  479. SND_SOC_DAPM_AIF_OUT("AIF1TX", "Analog Codec Capture", 0,
  480. SND_SOC_NOPM, 0, 0),
  481. SND_SOC_DAPM_AIF_OUT("AIF2TX", "Digital Codec Capture", 0,
  482. SND_SOC_NOPM, 0, 0),
  483. SND_SOC_DAPM_AIF_OUT("AIF3TX", "Alt Analog Codec Capture", 0,
  484. SND_SOC_NOPM, 0, 0),
  485. /* Input Pins */
  486. SND_SOC_DAPM_INPUT("Codec Input Pin1"),
  487. SND_SOC_DAPM_INPUT("Codec Input Pin2"),
  488. SND_SOC_DAPM_INPUT("Codec Input Pin3"),
  489. /* Output Pins */
  490. SND_SOC_DAPM_OUTPUT("Codec Output Pin1"),
  491. SND_SOC_DAPM_OUTPUT("Codec Output Pin2"),
  492. SND_SOC_DAPM_OUTPUT("Codec Output Pin3"),
  493. };
  494. static const struct snd_soc_component_driver hdac_hda_codec = {
  495. .probe = hdac_hda_codec_probe,
  496. .remove = hdac_hda_codec_remove,
  497. .dapm_widgets = hdac_hda_dapm_widgets,
  498. .num_dapm_widgets = ARRAY_SIZE(hdac_hda_dapm_widgets),
  499. .dapm_routes = hdac_hda_dapm_routes,
  500. .num_dapm_routes = ARRAY_SIZE(hdac_hda_dapm_routes),
  501. .idle_bias_on = false,
  502. .endianness = 1,
  503. };
  504. static int hdac_hda_dev_probe(struct hdac_device *hdev)
  505. {
  506. struct hdac_ext_link *hlink;
  507. int ret;
  508. /* hold the ref while we probe */
  509. hlink = snd_hdac_ext_bus_get_link(hdev->bus, dev_name(&hdev->dev));
  510. if (!hlink) {
  511. dev_err(&hdev->dev, "hdac link not found\n");
  512. return -EIO;
  513. }
  514. snd_hdac_ext_bus_link_get(hdev->bus, hlink);
  515. /* ASoC specific initialization */
  516. ret = devm_snd_soc_register_component(&hdev->dev,
  517. &hdac_hda_codec, hdac_hda_dais,
  518. ARRAY_SIZE(hdac_hda_dais));
  519. if (ret < 0) {
  520. dev_err(&hdev->dev, "failed to register HDA codec %d\n", ret);
  521. return ret;
  522. }
  523. snd_hdac_ext_bus_link_put(hdev->bus, hlink);
  524. return ret;
  525. }
  526. static int hdac_hda_dev_remove(struct hdac_device *hdev)
  527. {
  528. /*
  529. * Resources are freed in hdac_hda_codec_remove(). This
  530. * function is kept to keep hda_codec_driver_remove() happy.
  531. */
  532. return 0;
  533. }
  534. static struct hdac_ext_bus_ops hdac_ops = {
  535. .hdev_attach = hdac_hda_dev_probe,
  536. .hdev_detach = hdac_hda_dev_remove,
  537. };
  538. struct hdac_ext_bus_ops *snd_soc_hdac_hda_get_ops(void)
  539. {
  540. return &hdac_ops;
  541. }
  542. EXPORT_SYMBOL_GPL(snd_soc_hdac_hda_get_ops);
  543. MODULE_LICENSE("GPL v2");
  544. MODULE_DESCRIPTION("ASoC Extensions for legacy HDA Drivers");
  545. MODULE_AUTHOR("Rakesh Ughreja<[email protected]>");