skl-pcm.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. /*
  2. * skl-pcm.c -ASoC HDA Platform driver file implementing PCM functionality
  3. *
  4. * Copyright (C) 2014-2015 Intel Corp
  5. * Author: Jeeja KP <jeeja.kp@intel.com>
  6. *
  7. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; version 2 of the License.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. *
  20. */
  21. #include <linux/pci.h>
  22. #include <linux/pm_runtime.h>
  23. #include <sound/pcm_params.h>
  24. #include <sound/soc.h>
  25. #include "skl.h"
  26. #include "skl-topology.h"
  27. #include "skl-sst-dsp.h"
  28. #include "skl-sst-ipc.h"
  29. #define HDA_MONO 1
  30. #define HDA_STEREO 2
  31. #define HDA_QUAD 4
  32. static struct snd_pcm_hardware azx_pcm_hw = {
  33. .info = (SNDRV_PCM_INFO_MMAP |
  34. SNDRV_PCM_INFO_INTERLEAVED |
  35. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  36. SNDRV_PCM_INFO_MMAP_VALID |
  37. SNDRV_PCM_INFO_PAUSE |
  38. SNDRV_PCM_INFO_RESUME |
  39. SNDRV_PCM_INFO_SYNC_START |
  40. SNDRV_PCM_INFO_HAS_WALL_CLOCK | /* legacy */
  41. SNDRV_PCM_INFO_HAS_LINK_ATIME |
  42. SNDRV_PCM_INFO_NO_PERIOD_WAKEUP),
  43. .formats = SNDRV_PCM_FMTBIT_S16_LE |
  44. SNDRV_PCM_FMTBIT_S32_LE |
  45. SNDRV_PCM_FMTBIT_S24_LE,
  46. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000 |
  47. SNDRV_PCM_RATE_8000,
  48. .rate_min = 8000,
  49. .rate_max = 48000,
  50. .channels_min = 1,
  51. .channels_max = 8,
  52. .buffer_bytes_max = AZX_MAX_BUF_SIZE,
  53. .period_bytes_min = 128,
  54. .period_bytes_max = AZX_MAX_BUF_SIZE / 2,
  55. .periods_min = 2,
  56. .periods_max = AZX_MAX_FRAG,
  57. .fifo_size = 0,
  58. };
  59. static inline
  60. struct hdac_ext_stream *get_hdac_ext_stream(struct snd_pcm_substream *substream)
  61. {
  62. return substream->runtime->private_data;
  63. }
  64. static struct hdac_ext_bus *get_bus_ctx(struct snd_pcm_substream *substream)
  65. {
  66. struct hdac_ext_stream *stream = get_hdac_ext_stream(substream);
  67. struct hdac_stream *hstream = hdac_stream(stream);
  68. struct hdac_bus *bus = hstream->bus;
  69. return hbus_to_ebus(bus);
  70. }
  71. static int skl_substream_alloc_pages(struct hdac_ext_bus *ebus,
  72. struct snd_pcm_substream *substream,
  73. size_t size)
  74. {
  75. struct hdac_ext_stream *stream = get_hdac_ext_stream(substream);
  76. hdac_stream(stream)->bufsize = 0;
  77. hdac_stream(stream)->period_bytes = 0;
  78. hdac_stream(stream)->format_val = 0;
  79. return snd_pcm_lib_malloc_pages(substream, size);
  80. }
  81. static int skl_substream_free_pages(struct hdac_bus *bus,
  82. struct snd_pcm_substream *substream)
  83. {
  84. return snd_pcm_lib_free_pages(substream);
  85. }
  86. static void skl_set_pcm_constrains(struct hdac_ext_bus *ebus,
  87. struct snd_pcm_runtime *runtime)
  88. {
  89. snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
  90. /* avoid wrap-around with wall-clock */
  91. snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_TIME,
  92. 20, 178000000);
  93. }
  94. static enum hdac_ext_stream_type skl_get_host_stream_type(struct hdac_ext_bus *ebus)
  95. {
  96. if ((ebus_to_hbus(ebus))->ppcap)
  97. return HDAC_EXT_STREAM_TYPE_HOST;
  98. else
  99. return HDAC_EXT_STREAM_TYPE_COUPLED;
  100. }
  101. /*
  102. * check if the stream opened is marked as ignore_suspend by machine, if so
  103. * then enable suspend_active refcount
  104. *
  105. * The count supend_active does not need lock as it is used in open/close
  106. * and suspend context
  107. */
  108. static void skl_set_suspend_active(struct snd_pcm_substream *substream,
  109. struct snd_soc_dai *dai, bool enable)
  110. {
  111. struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
  112. struct snd_soc_dapm_widget *w;
  113. struct skl *skl = ebus_to_skl(ebus);
  114. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  115. w = dai->playback_widget;
  116. else
  117. w = dai->capture_widget;
  118. if (w->ignore_suspend && enable)
  119. skl->supend_active++;
  120. else if (w->ignore_suspend && !enable)
  121. skl->supend_active--;
  122. }
  123. static int skl_pcm_open(struct snd_pcm_substream *substream,
  124. struct snd_soc_dai *dai)
  125. {
  126. struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
  127. struct hdac_ext_stream *stream;
  128. struct snd_pcm_runtime *runtime = substream->runtime;
  129. struct skl_dma_params *dma_params;
  130. dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
  131. stream = snd_hdac_ext_stream_assign(ebus, substream,
  132. skl_get_host_stream_type(ebus));
  133. if (stream == NULL)
  134. return -EBUSY;
  135. skl_set_pcm_constrains(ebus, runtime);
  136. /*
  137. * disable WALLCLOCK timestamps for capture streams
  138. * until we figure out how to handle digital inputs
  139. */
  140. if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
  141. runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK; /* legacy */
  142. runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_LINK_ATIME;
  143. }
  144. runtime->private_data = stream;
  145. dma_params = kzalloc(sizeof(*dma_params), GFP_KERNEL);
  146. if (!dma_params)
  147. return -ENOMEM;
  148. dma_params->stream_tag = hdac_stream(stream)->stream_tag;
  149. snd_soc_dai_set_dma_data(dai, substream, dma_params);
  150. dev_dbg(dai->dev, "stream tag set in dma params=%d\n",
  151. dma_params->stream_tag);
  152. skl_set_suspend_active(substream, dai, true);
  153. snd_pcm_set_sync(substream);
  154. return 0;
  155. }
  156. static int skl_get_format(struct snd_pcm_substream *substream,
  157. struct snd_soc_dai *dai)
  158. {
  159. struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream);
  160. struct skl_dma_params *dma_params;
  161. struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
  162. int format_val = 0;
  163. if ((ebus_to_hbus(ebus))->ppcap) {
  164. struct snd_pcm_runtime *runtime = substream->runtime;
  165. format_val = snd_hdac_calc_stream_format(runtime->rate,
  166. runtime->channels,
  167. runtime->format,
  168. 32, 0);
  169. } else {
  170. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  171. dma_params = snd_soc_dai_get_dma_data(codec_dai, substream);
  172. if (dma_params)
  173. format_val = dma_params->format;
  174. }
  175. return format_val;
  176. }
  177. static int skl_be_prepare(struct snd_pcm_substream *substream,
  178. struct snd_soc_dai *dai)
  179. {
  180. struct skl *skl = get_skl_ctx(dai->dev);
  181. struct skl_sst *ctx = skl->skl_sst;
  182. struct skl_module_cfg *mconfig;
  183. if (dai->playback_widget->power || dai->capture_widget->power)
  184. return 0;
  185. mconfig = skl_tplg_be_get_cpr_module(dai, substream->stream);
  186. if (mconfig == NULL)
  187. return -EINVAL;
  188. return skl_dsp_set_dma_control(ctx, mconfig);
  189. }
  190. static int skl_pcm_prepare(struct snd_pcm_substream *substream,
  191. struct snd_soc_dai *dai)
  192. {
  193. struct hdac_ext_stream *stream = get_hdac_ext_stream(substream);
  194. struct skl *skl = get_skl_ctx(dai->dev);
  195. unsigned int format_val;
  196. int err;
  197. struct skl_module_cfg *mconfig;
  198. dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
  199. mconfig = skl_tplg_fe_get_cpr_module(dai, substream->stream);
  200. format_val = skl_get_format(substream, dai);
  201. dev_dbg(dai->dev, "stream_tag=%d formatvalue=%d\n",
  202. hdac_stream(stream)->stream_tag, format_val);
  203. snd_hdac_stream_reset(hdac_stream(stream));
  204. /* In case of XRUN recovery, reset the FW pipe to clean state */
  205. if (mconfig && (substream->runtime->status->state ==
  206. SNDRV_PCM_STATE_XRUN))
  207. skl_reset_pipe(skl->skl_sst, mconfig->pipe);
  208. err = snd_hdac_stream_set_params(hdac_stream(stream), format_val);
  209. if (err < 0)
  210. return err;
  211. err = snd_hdac_stream_setup(hdac_stream(stream));
  212. if (err < 0)
  213. return err;
  214. hdac_stream(stream)->prepared = 1;
  215. return err;
  216. }
  217. static int skl_pcm_hw_params(struct snd_pcm_substream *substream,
  218. struct snd_pcm_hw_params *params,
  219. struct snd_soc_dai *dai)
  220. {
  221. struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
  222. struct hdac_ext_stream *stream = get_hdac_ext_stream(substream);
  223. struct snd_pcm_runtime *runtime = substream->runtime;
  224. struct skl_pipe_params p_params = {0};
  225. struct skl_module_cfg *m_cfg;
  226. int ret, dma_id;
  227. dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
  228. ret = skl_substream_alloc_pages(ebus, substream,
  229. params_buffer_bytes(params));
  230. if (ret < 0)
  231. return ret;
  232. dev_dbg(dai->dev, "format_val, rate=%d, ch=%d, format=%d\n",
  233. runtime->rate, runtime->channels, runtime->format);
  234. dma_id = hdac_stream(stream)->stream_tag - 1;
  235. dev_dbg(dai->dev, "dma_id=%d\n", dma_id);
  236. p_params.s_fmt = snd_pcm_format_width(params_format(params));
  237. p_params.ch = params_channels(params);
  238. p_params.s_freq = params_rate(params);
  239. p_params.host_dma_id = dma_id;
  240. p_params.stream = substream->stream;
  241. m_cfg = skl_tplg_fe_get_cpr_module(dai, p_params.stream);
  242. if (m_cfg)
  243. skl_tplg_update_pipe_params(dai->dev, m_cfg, &p_params);
  244. return 0;
  245. }
  246. static void skl_pcm_close(struct snd_pcm_substream *substream,
  247. struct snd_soc_dai *dai)
  248. {
  249. struct hdac_ext_stream *stream = get_hdac_ext_stream(substream);
  250. struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
  251. struct skl_dma_params *dma_params = NULL;
  252. struct skl *skl = ebus_to_skl(ebus);
  253. dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
  254. snd_hdac_ext_stream_release(stream, skl_get_host_stream_type(ebus));
  255. dma_params = snd_soc_dai_get_dma_data(dai, substream);
  256. /*
  257. * now we should set this to NULL as we are freeing by the
  258. * dma_params
  259. */
  260. snd_soc_dai_set_dma_data(dai, substream, NULL);
  261. skl_set_suspend_active(substream, dai, false);
  262. /*
  263. * check if close is for "Reference Pin" and set back the
  264. * CGCTL.MISCBDCGE if disabled by driver
  265. */
  266. if (!strncmp(dai->name, "Reference Pin", 13) &&
  267. skl->skl_sst->miscbdcg_disabled) {
  268. skl->skl_sst->enable_miscbdcge(dai->dev, true);
  269. skl->skl_sst->miscbdcg_disabled = false;
  270. }
  271. kfree(dma_params);
  272. }
  273. static int skl_pcm_hw_free(struct snd_pcm_substream *substream,
  274. struct snd_soc_dai *dai)
  275. {
  276. struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
  277. struct hdac_ext_stream *stream = get_hdac_ext_stream(substream);
  278. dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
  279. snd_hdac_stream_cleanup(hdac_stream(stream));
  280. hdac_stream(stream)->prepared = 0;
  281. return skl_substream_free_pages(ebus_to_hbus(ebus), substream);
  282. }
  283. static int skl_be_hw_params(struct snd_pcm_substream *substream,
  284. struct snd_pcm_hw_params *params,
  285. struct snd_soc_dai *dai)
  286. {
  287. struct skl_pipe_params p_params = {0};
  288. p_params.s_fmt = snd_pcm_format_width(params_format(params));
  289. p_params.ch = params_channels(params);
  290. p_params.s_freq = params_rate(params);
  291. p_params.stream = substream->stream;
  292. return skl_tplg_be_update_params(dai, &p_params);
  293. }
  294. static int skl_decoupled_trigger(struct snd_pcm_substream *substream,
  295. int cmd)
  296. {
  297. struct hdac_ext_bus *ebus = get_bus_ctx(substream);
  298. struct hdac_bus *bus = ebus_to_hbus(ebus);
  299. struct hdac_ext_stream *stream;
  300. int start;
  301. unsigned long cookie;
  302. struct hdac_stream *hstr;
  303. stream = get_hdac_ext_stream(substream);
  304. hstr = hdac_stream(stream);
  305. if (!hstr->prepared)
  306. return -EPIPE;
  307. switch (cmd) {
  308. case SNDRV_PCM_TRIGGER_START:
  309. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  310. case SNDRV_PCM_TRIGGER_RESUME:
  311. start = 1;
  312. break;
  313. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  314. case SNDRV_PCM_TRIGGER_SUSPEND:
  315. case SNDRV_PCM_TRIGGER_STOP:
  316. start = 0;
  317. break;
  318. default:
  319. return -EINVAL;
  320. }
  321. spin_lock_irqsave(&bus->reg_lock, cookie);
  322. if (start) {
  323. snd_hdac_stream_start(hdac_stream(stream), true);
  324. snd_hdac_stream_timecounter_init(hstr, 0);
  325. } else {
  326. snd_hdac_stream_stop(hdac_stream(stream));
  327. }
  328. spin_unlock_irqrestore(&bus->reg_lock, cookie);
  329. return 0;
  330. }
  331. static int skl_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
  332. struct snd_soc_dai *dai)
  333. {
  334. struct skl *skl = get_skl_ctx(dai->dev);
  335. struct skl_sst *ctx = skl->skl_sst;
  336. struct skl_module_cfg *mconfig;
  337. struct hdac_ext_bus *ebus = get_bus_ctx(substream);
  338. struct hdac_ext_stream *stream = get_hdac_ext_stream(substream);
  339. struct snd_soc_dapm_widget *w;
  340. int ret;
  341. mconfig = skl_tplg_fe_get_cpr_module(dai, substream->stream);
  342. if (!mconfig)
  343. return -EIO;
  344. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  345. w = dai->playback_widget;
  346. else
  347. w = dai->capture_widget;
  348. switch (cmd) {
  349. case SNDRV_PCM_TRIGGER_RESUME:
  350. if (!w->ignore_suspend) {
  351. skl_pcm_prepare(substream, dai);
  352. /*
  353. * enable DMA Resume enable bit for the stream, set the
  354. * dpib & lpib position to resume before starting the
  355. * DMA
  356. */
  357. snd_hdac_ext_stream_drsm_enable(ebus, true,
  358. hdac_stream(stream)->index);
  359. snd_hdac_ext_stream_set_dpibr(ebus, stream,
  360. stream->dpib);
  361. snd_hdac_ext_stream_set_lpib(stream, stream->lpib);
  362. }
  363. case SNDRV_PCM_TRIGGER_START:
  364. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  365. /*
  366. * Start HOST DMA and Start FE Pipe.This is to make sure that
  367. * there are no underrun/overrun in the case when the FE
  368. * pipeline is started but there is a delay in starting the
  369. * DMA channel on the host.
  370. */
  371. snd_hdac_ext_stream_decouple(ebus, stream, true);
  372. ret = skl_decoupled_trigger(substream, cmd);
  373. if (ret < 0)
  374. return ret;
  375. return skl_run_pipe(ctx, mconfig->pipe);
  376. break;
  377. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  378. case SNDRV_PCM_TRIGGER_SUSPEND:
  379. case SNDRV_PCM_TRIGGER_STOP:
  380. /*
  381. * Stop FE Pipe first and stop DMA. This is to make sure that
  382. * there are no underrun/overrun in the case if there is a delay
  383. * between the two operations.
  384. */
  385. ret = skl_stop_pipe(ctx, mconfig->pipe);
  386. if (ret < 0)
  387. return ret;
  388. ret = skl_decoupled_trigger(substream, cmd);
  389. if ((cmd == SNDRV_PCM_TRIGGER_SUSPEND) && !w->ignore_suspend) {
  390. /* save the dpib and lpib positions */
  391. stream->dpib = readl(ebus->bus.remap_addr +
  392. AZX_REG_VS_SDXDPIB_XBASE +
  393. (AZX_REG_VS_SDXDPIB_XINTERVAL *
  394. hdac_stream(stream)->index));
  395. stream->lpib = snd_hdac_stream_get_pos_lpib(
  396. hdac_stream(stream));
  397. snd_hdac_ext_stream_decouple(ebus, stream, false);
  398. }
  399. break;
  400. default:
  401. return -EINVAL;
  402. }
  403. return 0;
  404. }
  405. static int skl_link_hw_params(struct snd_pcm_substream *substream,
  406. struct snd_pcm_hw_params *params,
  407. struct snd_soc_dai *dai)
  408. {
  409. struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
  410. struct hdac_ext_stream *link_dev;
  411. struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream);
  412. struct hdac_ext_dma_params *dma_params;
  413. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  414. struct skl_pipe_params p_params = {0};
  415. link_dev = snd_hdac_ext_stream_assign(ebus, substream,
  416. HDAC_EXT_STREAM_TYPE_LINK);
  417. if (!link_dev)
  418. return -EBUSY;
  419. snd_soc_dai_set_dma_data(dai, substream, (void *)link_dev);
  420. /* set the stream tag in the codec dai dma params */
  421. dma_params = snd_soc_dai_get_dma_data(codec_dai, substream);
  422. if (dma_params)
  423. dma_params->stream_tag = hdac_stream(link_dev)->stream_tag;
  424. p_params.s_fmt = snd_pcm_format_width(params_format(params));
  425. p_params.ch = params_channels(params);
  426. p_params.s_freq = params_rate(params);
  427. p_params.stream = substream->stream;
  428. p_params.link_dma_id = hdac_stream(link_dev)->stream_tag - 1;
  429. return skl_tplg_be_update_params(dai, &p_params);
  430. }
  431. static int skl_link_pcm_prepare(struct snd_pcm_substream *substream,
  432. struct snd_soc_dai *dai)
  433. {
  434. struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream);
  435. struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
  436. struct hdac_ext_stream *link_dev =
  437. snd_soc_dai_get_dma_data(dai, substream);
  438. unsigned int format_val = 0;
  439. struct skl_dma_params *dma_params;
  440. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  441. struct hdac_ext_link *link;
  442. struct skl *skl = get_skl_ctx(dai->dev);
  443. struct skl_module_cfg *mconfig = NULL;
  444. dma_params = (struct skl_dma_params *)
  445. snd_soc_dai_get_dma_data(codec_dai, substream);
  446. if (dma_params)
  447. format_val = dma_params->format;
  448. dev_dbg(dai->dev, "stream_tag=%d formatvalue=%d codec_dai_name=%s\n",
  449. hdac_stream(link_dev)->stream_tag, format_val, codec_dai->name);
  450. link = snd_hdac_ext_bus_get_link(ebus, rtd->codec->component.name);
  451. if (!link)
  452. return -EINVAL;
  453. snd_hdac_ext_link_stream_reset(link_dev);
  454. /* In case of XRUN recovery, reset the FW pipe to clean state */
  455. mconfig = skl_tplg_be_get_cpr_module(dai, substream->stream);
  456. if (mconfig && (substream->runtime->status->state ==
  457. SNDRV_PCM_STATE_XRUN))
  458. skl_reset_pipe(skl->skl_sst, mconfig->pipe);
  459. snd_hdac_ext_link_stream_setup(link_dev, format_val);
  460. snd_hdac_ext_link_set_stream_id(link, hdac_stream(link_dev)->stream_tag);
  461. link_dev->link_prepared = 1;
  462. return 0;
  463. }
  464. static int skl_link_pcm_trigger(struct snd_pcm_substream *substream,
  465. int cmd, struct snd_soc_dai *dai)
  466. {
  467. struct hdac_ext_stream *link_dev =
  468. snd_soc_dai_get_dma_data(dai, substream);
  469. struct hdac_ext_bus *ebus = get_bus_ctx(substream);
  470. struct hdac_ext_stream *stream = get_hdac_ext_stream(substream);
  471. dev_dbg(dai->dev, "In %s cmd=%d\n", __func__, cmd);
  472. switch (cmd) {
  473. case SNDRV_PCM_TRIGGER_RESUME:
  474. skl_link_pcm_prepare(substream, dai);
  475. case SNDRV_PCM_TRIGGER_START:
  476. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  477. snd_hdac_ext_stream_decouple(ebus, stream, true);
  478. snd_hdac_ext_link_stream_start(link_dev);
  479. break;
  480. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  481. case SNDRV_PCM_TRIGGER_SUSPEND:
  482. case SNDRV_PCM_TRIGGER_STOP:
  483. snd_hdac_ext_link_stream_clear(link_dev);
  484. if (cmd == SNDRV_PCM_TRIGGER_SUSPEND)
  485. snd_hdac_ext_stream_decouple(ebus, stream, false);
  486. break;
  487. default:
  488. return -EINVAL;
  489. }
  490. return 0;
  491. }
  492. static int skl_link_hw_free(struct snd_pcm_substream *substream,
  493. struct snd_soc_dai *dai)
  494. {
  495. struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
  496. struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream);
  497. struct hdac_ext_stream *link_dev =
  498. snd_soc_dai_get_dma_data(dai, substream);
  499. struct hdac_ext_link *link;
  500. dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
  501. link_dev->link_prepared = 0;
  502. link = snd_hdac_ext_bus_get_link(ebus, rtd->codec->component.name);
  503. if (!link)
  504. return -EINVAL;
  505. snd_hdac_ext_link_clear_stream_id(link, hdac_stream(link_dev)->stream_tag);
  506. snd_hdac_ext_stream_release(link_dev, HDAC_EXT_STREAM_TYPE_LINK);
  507. return 0;
  508. }
  509. static struct snd_soc_dai_ops skl_pcm_dai_ops = {
  510. .startup = skl_pcm_open,
  511. .shutdown = skl_pcm_close,
  512. .prepare = skl_pcm_prepare,
  513. .hw_params = skl_pcm_hw_params,
  514. .hw_free = skl_pcm_hw_free,
  515. .trigger = skl_pcm_trigger,
  516. };
  517. static struct snd_soc_dai_ops skl_dmic_dai_ops = {
  518. .hw_params = skl_be_hw_params,
  519. };
  520. static struct snd_soc_dai_ops skl_be_ssp_dai_ops = {
  521. .hw_params = skl_be_hw_params,
  522. .prepare = skl_be_prepare,
  523. };
  524. static struct snd_soc_dai_ops skl_link_dai_ops = {
  525. .prepare = skl_link_pcm_prepare,
  526. .hw_params = skl_link_hw_params,
  527. .hw_free = skl_link_hw_free,
  528. .trigger = skl_link_pcm_trigger,
  529. };
  530. static struct snd_soc_dai_driver skl_platform_dai[] = {
  531. {
  532. .name = "System Pin",
  533. .ops = &skl_pcm_dai_ops,
  534. .playback = {
  535. .stream_name = "System Playback",
  536. .channels_min = HDA_MONO,
  537. .channels_max = HDA_STEREO,
  538. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_8000,
  539. .formats = SNDRV_PCM_FMTBIT_S16_LE |
  540. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE,
  541. },
  542. .capture = {
  543. .stream_name = "System Capture",
  544. .channels_min = HDA_MONO,
  545. .channels_max = HDA_STEREO,
  546. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000,
  547. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
  548. },
  549. },
  550. {
  551. .name = "Reference Pin",
  552. .ops = &skl_pcm_dai_ops,
  553. .capture = {
  554. .stream_name = "Reference Capture",
  555. .channels_min = HDA_MONO,
  556. .channels_max = HDA_QUAD,
  557. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000,
  558. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
  559. },
  560. },
  561. {
  562. .name = "Deepbuffer Pin",
  563. .ops = &skl_pcm_dai_ops,
  564. .playback = {
  565. .stream_name = "Deepbuffer Playback",
  566. .channels_min = HDA_STEREO,
  567. .channels_max = HDA_STEREO,
  568. .rates = SNDRV_PCM_RATE_48000,
  569. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
  570. },
  571. },
  572. {
  573. .name = "LowLatency Pin",
  574. .ops = &skl_pcm_dai_ops,
  575. .playback = {
  576. .stream_name = "Low Latency Playback",
  577. .channels_min = HDA_STEREO,
  578. .channels_max = HDA_STEREO,
  579. .rates = SNDRV_PCM_RATE_48000,
  580. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
  581. },
  582. },
  583. {
  584. .name = "DMIC Pin",
  585. .ops = &skl_pcm_dai_ops,
  586. .capture = {
  587. .stream_name = "DMIC Capture",
  588. .channels_min = HDA_MONO,
  589. .channels_max = HDA_QUAD,
  590. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000,
  591. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
  592. },
  593. },
  594. {
  595. .name = "HDMI1 Pin",
  596. .ops = &skl_pcm_dai_ops,
  597. .playback = {
  598. .stream_name = "HDMI1 Playback",
  599. .channels_min = HDA_STEREO,
  600. .channels_max = 8,
  601. .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |
  602. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |
  603. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |
  604. SNDRV_PCM_RATE_192000,
  605. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |
  606. SNDRV_PCM_FMTBIT_S32_LE,
  607. },
  608. },
  609. {
  610. .name = "HDMI2 Pin",
  611. .ops = &skl_pcm_dai_ops,
  612. .playback = {
  613. .stream_name = "HDMI2 Playback",
  614. .channels_min = HDA_STEREO,
  615. .channels_max = 8,
  616. .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |
  617. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |
  618. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |
  619. SNDRV_PCM_RATE_192000,
  620. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |
  621. SNDRV_PCM_FMTBIT_S32_LE,
  622. },
  623. },
  624. {
  625. .name = "HDMI3 Pin",
  626. .ops = &skl_pcm_dai_ops,
  627. .playback = {
  628. .stream_name = "HDMI3 Playback",
  629. .channels_min = HDA_STEREO,
  630. .channels_max = 8,
  631. .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |
  632. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |
  633. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |
  634. SNDRV_PCM_RATE_192000,
  635. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |
  636. SNDRV_PCM_FMTBIT_S32_LE,
  637. },
  638. },
  639. /* BE CPU Dais */
  640. {
  641. .name = "SSP0 Pin",
  642. .ops = &skl_be_ssp_dai_ops,
  643. .playback = {
  644. .stream_name = "ssp0 Tx",
  645. .channels_min = HDA_STEREO,
  646. .channels_max = HDA_STEREO,
  647. .rates = SNDRV_PCM_RATE_48000,
  648. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  649. },
  650. .capture = {
  651. .stream_name = "ssp0 Rx",
  652. .channels_min = HDA_STEREO,
  653. .channels_max = HDA_STEREO,
  654. .rates = SNDRV_PCM_RATE_48000,
  655. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  656. },
  657. },
  658. {
  659. .name = "SSP1 Pin",
  660. .ops = &skl_be_ssp_dai_ops,
  661. .playback = {
  662. .stream_name = "ssp1 Tx",
  663. .channels_min = HDA_STEREO,
  664. .channels_max = HDA_STEREO,
  665. .rates = SNDRV_PCM_RATE_48000,
  666. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  667. },
  668. .capture = {
  669. .stream_name = "ssp1 Rx",
  670. .channels_min = HDA_STEREO,
  671. .channels_max = HDA_STEREO,
  672. .rates = SNDRV_PCM_RATE_48000,
  673. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  674. },
  675. },
  676. {
  677. .name = "SSP2 Pin",
  678. .ops = &skl_be_ssp_dai_ops,
  679. .playback = {
  680. .stream_name = "ssp2 Tx",
  681. .channels_min = HDA_STEREO,
  682. .channels_max = HDA_STEREO,
  683. .rates = SNDRV_PCM_RATE_48000,
  684. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  685. },
  686. .capture = {
  687. .stream_name = "ssp2 Rx",
  688. .channels_min = HDA_STEREO,
  689. .channels_max = HDA_STEREO,
  690. .rates = SNDRV_PCM_RATE_48000,
  691. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  692. },
  693. },
  694. {
  695. .name = "SSP3 Pin",
  696. .ops = &skl_be_ssp_dai_ops,
  697. .playback = {
  698. .stream_name = "ssp3 Tx",
  699. .channels_min = HDA_STEREO,
  700. .channels_max = HDA_STEREO,
  701. .rates = SNDRV_PCM_RATE_48000,
  702. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  703. },
  704. .capture = {
  705. .stream_name = "ssp3 Rx",
  706. .channels_min = HDA_STEREO,
  707. .channels_max = HDA_STEREO,
  708. .rates = SNDRV_PCM_RATE_48000,
  709. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  710. },
  711. },
  712. {
  713. .name = "SSP4 Pin",
  714. .ops = &skl_be_ssp_dai_ops,
  715. .playback = {
  716. .stream_name = "ssp4 Tx",
  717. .channels_min = HDA_STEREO,
  718. .channels_max = HDA_STEREO,
  719. .rates = SNDRV_PCM_RATE_48000,
  720. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  721. },
  722. .capture = {
  723. .stream_name = "ssp4 Rx",
  724. .channels_min = HDA_STEREO,
  725. .channels_max = HDA_STEREO,
  726. .rates = SNDRV_PCM_RATE_48000,
  727. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  728. },
  729. },
  730. {
  731. .name = "SSP5 Pin",
  732. .ops = &skl_be_ssp_dai_ops,
  733. .playback = {
  734. .stream_name = "ssp5 Tx",
  735. .channels_min = HDA_STEREO,
  736. .channels_max = HDA_STEREO,
  737. .rates = SNDRV_PCM_RATE_48000,
  738. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  739. },
  740. .capture = {
  741. .stream_name = "ssp5 Rx",
  742. .channels_min = HDA_STEREO,
  743. .channels_max = HDA_STEREO,
  744. .rates = SNDRV_PCM_RATE_48000,
  745. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  746. },
  747. },
  748. {
  749. .name = "iDisp1 Pin",
  750. .ops = &skl_link_dai_ops,
  751. .playback = {
  752. .stream_name = "iDisp1 Tx",
  753. .channels_min = HDA_STEREO,
  754. .channels_max = 8,
  755. .rates = SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_48000,
  756. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE |
  757. SNDRV_PCM_FMTBIT_S24_LE,
  758. },
  759. },
  760. {
  761. .name = "iDisp2 Pin",
  762. .ops = &skl_link_dai_ops,
  763. .playback = {
  764. .stream_name = "iDisp2 Tx",
  765. .channels_min = HDA_STEREO,
  766. .channels_max = 8,
  767. .rates = SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|
  768. SNDRV_PCM_RATE_48000,
  769. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE |
  770. SNDRV_PCM_FMTBIT_S24_LE,
  771. },
  772. },
  773. {
  774. .name = "iDisp3 Pin",
  775. .ops = &skl_link_dai_ops,
  776. .playback = {
  777. .stream_name = "iDisp3 Tx",
  778. .channels_min = HDA_STEREO,
  779. .channels_max = 8,
  780. .rates = SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|
  781. SNDRV_PCM_RATE_48000,
  782. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE |
  783. SNDRV_PCM_FMTBIT_S24_LE,
  784. },
  785. },
  786. {
  787. .name = "DMIC01 Pin",
  788. .ops = &skl_dmic_dai_ops,
  789. .capture = {
  790. .stream_name = "DMIC01 Rx",
  791. .channels_min = HDA_MONO,
  792. .channels_max = HDA_QUAD,
  793. .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000,
  794. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
  795. },
  796. },
  797. {
  798. .name = "HD-Codec Pin",
  799. .ops = &skl_link_dai_ops,
  800. .playback = {
  801. .stream_name = "HD-Codec Tx",
  802. .channels_min = HDA_STEREO,
  803. .channels_max = HDA_STEREO,
  804. .rates = SNDRV_PCM_RATE_48000,
  805. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  806. },
  807. .capture = {
  808. .stream_name = "HD-Codec Rx",
  809. .channels_min = HDA_STEREO,
  810. .channels_max = HDA_STEREO,
  811. .rates = SNDRV_PCM_RATE_48000,
  812. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  813. },
  814. },
  815. };
  816. static int skl_platform_open(struct snd_pcm_substream *substream)
  817. {
  818. struct snd_pcm_runtime *runtime;
  819. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  820. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  821. dev_dbg(rtd->cpu_dai->dev, "In %s:%s\n", __func__,
  822. dai_link->cpu_dai_name);
  823. runtime = substream->runtime;
  824. snd_soc_set_runtime_hwparams(substream, &azx_pcm_hw);
  825. return 0;
  826. }
  827. static int skl_coupled_trigger(struct snd_pcm_substream *substream,
  828. int cmd)
  829. {
  830. struct hdac_ext_bus *ebus = get_bus_ctx(substream);
  831. struct hdac_bus *bus = ebus_to_hbus(ebus);
  832. struct hdac_ext_stream *stream;
  833. struct snd_pcm_substream *s;
  834. bool start;
  835. int sbits = 0;
  836. unsigned long cookie;
  837. struct hdac_stream *hstr;
  838. stream = get_hdac_ext_stream(substream);
  839. hstr = hdac_stream(stream);
  840. dev_dbg(bus->dev, "In %s cmd=%d\n", __func__, cmd);
  841. if (!hstr->prepared)
  842. return -EPIPE;
  843. switch (cmd) {
  844. case SNDRV_PCM_TRIGGER_START:
  845. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  846. case SNDRV_PCM_TRIGGER_RESUME:
  847. start = true;
  848. break;
  849. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  850. case SNDRV_PCM_TRIGGER_SUSPEND:
  851. case SNDRV_PCM_TRIGGER_STOP:
  852. start = false;
  853. break;
  854. default:
  855. return -EINVAL;
  856. }
  857. snd_pcm_group_for_each_entry(s, substream) {
  858. if (s->pcm->card != substream->pcm->card)
  859. continue;
  860. stream = get_hdac_ext_stream(s);
  861. sbits |= 1 << hdac_stream(stream)->index;
  862. snd_pcm_trigger_done(s, substream);
  863. }
  864. spin_lock_irqsave(&bus->reg_lock, cookie);
  865. /* first, set SYNC bits of corresponding streams */
  866. snd_hdac_stream_sync_trigger(hstr, true, sbits, AZX_REG_SSYNC);
  867. snd_pcm_group_for_each_entry(s, substream) {
  868. if (s->pcm->card != substream->pcm->card)
  869. continue;
  870. stream = get_hdac_ext_stream(s);
  871. if (start)
  872. snd_hdac_stream_start(hdac_stream(stream), true);
  873. else
  874. snd_hdac_stream_stop(hdac_stream(stream));
  875. }
  876. spin_unlock_irqrestore(&bus->reg_lock, cookie);
  877. snd_hdac_stream_sync(hstr, start, sbits);
  878. spin_lock_irqsave(&bus->reg_lock, cookie);
  879. /* reset SYNC bits */
  880. snd_hdac_stream_sync_trigger(hstr, false, sbits, AZX_REG_SSYNC);
  881. if (start)
  882. snd_hdac_stream_timecounter_init(hstr, sbits);
  883. spin_unlock_irqrestore(&bus->reg_lock, cookie);
  884. return 0;
  885. }
  886. static int skl_platform_pcm_trigger(struct snd_pcm_substream *substream,
  887. int cmd)
  888. {
  889. struct hdac_ext_bus *ebus = get_bus_ctx(substream);
  890. if (!(ebus_to_hbus(ebus))->ppcap)
  891. return skl_coupled_trigger(substream, cmd);
  892. return 0;
  893. }
  894. static snd_pcm_uframes_t skl_platform_pcm_pointer
  895. (struct snd_pcm_substream *substream)
  896. {
  897. struct hdac_ext_stream *hstream = get_hdac_ext_stream(substream);
  898. unsigned int pos;
  899. /* use the position buffer as default */
  900. pos = snd_hdac_stream_get_pos_posbuf(hdac_stream(hstream));
  901. if (pos >= hdac_stream(hstream)->bufsize)
  902. pos = 0;
  903. return bytes_to_frames(substream->runtime, pos);
  904. }
  905. static u64 skl_adjust_codec_delay(struct snd_pcm_substream *substream,
  906. u64 nsec)
  907. {
  908. struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream);
  909. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  910. u64 codec_frames, codec_nsecs;
  911. if (!codec_dai->driver->ops->delay)
  912. return nsec;
  913. codec_frames = codec_dai->driver->ops->delay(substream, codec_dai);
  914. codec_nsecs = div_u64(codec_frames * 1000000000LL,
  915. substream->runtime->rate);
  916. if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  917. return nsec + codec_nsecs;
  918. return (nsec > codec_nsecs) ? nsec - codec_nsecs : 0;
  919. }
  920. static int skl_get_time_info(struct snd_pcm_substream *substream,
  921. struct timespec *system_ts, struct timespec *audio_ts,
  922. struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
  923. struct snd_pcm_audio_tstamp_report *audio_tstamp_report)
  924. {
  925. struct hdac_ext_stream *sstream = get_hdac_ext_stream(substream);
  926. struct hdac_stream *hstr = hdac_stream(sstream);
  927. u64 nsec;
  928. if ((substream->runtime->hw.info & SNDRV_PCM_INFO_HAS_LINK_ATIME) &&
  929. (audio_tstamp_config->type_requested == SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK)) {
  930. snd_pcm_gettime(substream->runtime, system_ts);
  931. nsec = timecounter_read(&hstr->tc);
  932. nsec = div_u64(nsec, 3); /* can be optimized */
  933. if (audio_tstamp_config->report_delay)
  934. nsec = skl_adjust_codec_delay(substream, nsec);
  935. *audio_ts = ns_to_timespec(nsec);
  936. audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK;
  937. audio_tstamp_report->accuracy_report = 1; /* rest of struct is valid */
  938. audio_tstamp_report->accuracy = 42; /* 24MHzWallClk == 42ns resolution */
  939. } else {
  940. audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT;
  941. }
  942. return 0;
  943. }
  944. static const struct snd_pcm_ops skl_platform_ops = {
  945. .open = skl_platform_open,
  946. .ioctl = snd_pcm_lib_ioctl,
  947. .trigger = skl_platform_pcm_trigger,
  948. .pointer = skl_platform_pcm_pointer,
  949. .get_time_info = skl_get_time_info,
  950. .mmap = snd_pcm_lib_default_mmap,
  951. .page = snd_pcm_sgbuf_ops_page,
  952. };
  953. static void skl_pcm_free(struct snd_pcm *pcm)
  954. {
  955. snd_pcm_lib_preallocate_free_for_all(pcm);
  956. }
  957. #define MAX_PREALLOC_SIZE (32 * 1024 * 1024)
  958. static int skl_pcm_new(struct snd_soc_pcm_runtime *rtd)
  959. {
  960. struct snd_soc_dai *dai = rtd->cpu_dai;
  961. struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
  962. struct snd_pcm *pcm = rtd->pcm;
  963. unsigned int size;
  964. int retval = 0;
  965. struct skl *skl = ebus_to_skl(ebus);
  966. if (dai->driver->playback.channels_min ||
  967. dai->driver->capture.channels_min) {
  968. /* buffer pre-allocation */
  969. size = CONFIG_SND_HDA_PREALLOC_SIZE * 1024;
  970. if (size > MAX_PREALLOC_SIZE)
  971. size = MAX_PREALLOC_SIZE;
  972. retval = snd_pcm_lib_preallocate_pages_for_all(pcm,
  973. SNDRV_DMA_TYPE_DEV_SG,
  974. snd_dma_pci_data(skl->pci),
  975. size, MAX_PREALLOC_SIZE);
  976. if (retval) {
  977. dev_err(dai->dev, "dma buffer allocationf fail\n");
  978. return retval;
  979. }
  980. }
  981. return retval;
  982. }
  983. static int skl_populate_modules(struct skl *skl)
  984. {
  985. struct skl_pipeline *p;
  986. struct skl_pipe_module *m;
  987. struct snd_soc_dapm_widget *w;
  988. struct skl_module_cfg *mconfig;
  989. int ret;
  990. list_for_each_entry(p, &skl->ppl_list, node) {
  991. list_for_each_entry(m, &p->pipe->w_list, node) {
  992. w = m->w;
  993. mconfig = w->priv;
  994. ret = snd_skl_get_module_info(skl->skl_sst, mconfig);
  995. if (ret < 0) {
  996. dev_err(skl->skl_sst->dev,
  997. "query module info failed:%d\n", ret);
  998. goto err;
  999. }
  1000. }
  1001. }
  1002. err:
  1003. return ret;
  1004. }
  1005. static int skl_platform_soc_probe(struct snd_soc_platform *platform)
  1006. {
  1007. struct hdac_ext_bus *ebus = dev_get_drvdata(platform->dev);
  1008. struct skl *skl = ebus_to_skl(ebus);
  1009. const struct skl_dsp_ops *ops;
  1010. int ret;
  1011. pm_runtime_get_sync(platform->dev);
  1012. if ((ebus_to_hbus(ebus))->ppcap) {
  1013. ret = skl_tplg_init(platform, ebus);
  1014. if (ret < 0) {
  1015. dev_err(platform->dev, "Failed to init topology!\n");
  1016. return ret;
  1017. }
  1018. skl->platform = platform;
  1019. /* load the firmwares, since all is set */
  1020. ops = skl_get_dsp_ops(skl->pci->device);
  1021. if (!ops)
  1022. return -EIO;
  1023. if (skl->skl_sst->is_first_boot == false) {
  1024. dev_err(platform->dev, "DSP reports first boot done!!!\n");
  1025. return -EIO;
  1026. }
  1027. /* disable dynamic clock gating during fw and lib download */
  1028. skl->skl_sst->enable_miscbdcge(platform->dev, false);
  1029. ret = ops->init_fw(platform->dev, skl->skl_sst);
  1030. skl->skl_sst->enable_miscbdcge(platform->dev, true);
  1031. if (ret < 0) {
  1032. dev_err(platform->dev, "Failed to boot first fw: %d\n", ret);
  1033. return ret;
  1034. }
  1035. skl_populate_modules(skl);
  1036. }
  1037. pm_runtime_mark_last_busy(platform->dev);
  1038. pm_runtime_put_autosuspend(platform->dev);
  1039. return 0;
  1040. }
  1041. static struct snd_soc_platform_driver skl_platform_drv = {
  1042. .probe = skl_platform_soc_probe,
  1043. .ops = &skl_platform_ops,
  1044. .pcm_new = skl_pcm_new,
  1045. .pcm_free = skl_pcm_free,
  1046. };
  1047. static const struct snd_soc_component_driver skl_component = {
  1048. .name = "pcm",
  1049. };
  1050. int skl_platform_register(struct device *dev)
  1051. {
  1052. int ret;
  1053. struct hdac_ext_bus *ebus = dev_get_drvdata(dev);
  1054. struct skl *skl = ebus_to_skl(ebus);
  1055. INIT_LIST_HEAD(&skl->ppl_list);
  1056. ret = snd_soc_register_platform(dev, &skl_platform_drv);
  1057. if (ret) {
  1058. dev_err(dev, "soc platform registration failed %d\n", ret);
  1059. return ret;
  1060. }
  1061. ret = snd_soc_register_component(dev, &skl_component,
  1062. skl_platform_dai,
  1063. ARRAY_SIZE(skl_platform_dai));
  1064. if (ret) {
  1065. dev_err(dev, "soc component registration failed %d\n", ret);
  1066. snd_soc_unregister_platform(dev);
  1067. }
  1068. return ret;
  1069. }
  1070. int skl_platform_unregister(struct device *dev)
  1071. {
  1072. snd_soc_unregister_component(dev);
  1073. snd_soc_unregister_platform(dev);
  1074. return 0;
  1075. }