sst_drv_interface.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /*
  2. * sst_drv_interface.c - Intel SST Driver for audio engine
  3. *
  4. * Copyright (C) 2008-14 Intel Corp
  5. * Authors: Vinod Koul <vinod.koul@intel.com>
  6. * Harsha Priya <priya.harsha@intel.com>
  7. * Dharageswari R <dharageswari.r@intel.com)
  8. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; version 2 of the License.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  20. */
  21. #include <linux/delay.h>
  22. #include <linux/pci.h>
  23. #include <linux/fs.h>
  24. #include <linux/firmware.h>
  25. #include <linux/pm_runtime.h>
  26. #include <linux/pm_qos.h>
  27. #include <linux/math64.h>
  28. #include <sound/core.h>
  29. #include <sound/pcm.h>
  30. #include <sound/soc.h>
  31. #include <sound/compress_driver.h>
  32. #include <asm/platform_sst_audio.h>
  33. #include "../sst-mfld-platform.h"
  34. #include "sst.h"
  35. #include "../../common/sst-dsp.h"
  36. #define NUM_CODEC 2
  37. #define MIN_FRAGMENT 2
  38. #define MAX_FRAGMENT 4
  39. #define MIN_FRAGMENT_SIZE (50 * 1024)
  40. #define MAX_FRAGMENT_SIZE (1024 * 1024)
  41. #define SST_GET_BYTES_PER_SAMPLE(pcm_wd_sz) (((pcm_wd_sz + 15) >> 4) << 1)
  42. #ifdef CONFIG_PM
  43. #define GET_USAGE_COUNT(dev) (atomic_read(&dev->power.usage_count))
  44. #else
  45. #define GET_USAGE_COUNT(dev) 1
  46. #endif
  47. int free_stream_context(struct intel_sst_drv *ctx, unsigned int str_id)
  48. {
  49. struct stream_info *stream;
  50. int ret = 0;
  51. stream = get_stream_info(ctx, str_id);
  52. if (stream) {
  53. /* str_id is valid, so stream is alloacted */
  54. ret = sst_free_stream(ctx, str_id);
  55. if (ret)
  56. sst_clean_stream(&ctx->streams[str_id]);
  57. return ret;
  58. } else {
  59. dev_err(ctx->dev, "we tried to free stream context %d which was freed!!!\n", str_id);
  60. }
  61. return ret;
  62. }
  63. int sst_get_stream_allocated(struct intel_sst_drv *ctx,
  64. struct snd_sst_params *str_param,
  65. struct snd_sst_lib_download **lib_dnld)
  66. {
  67. int retval;
  68. retval = ctx->ops->alloc_stream(ctx, str_param);
  69. if (retval > 0)
  70. dev_dbg(ctx->dev, "Stream allocated %d\n", retval);
  71. return retval;
  72. }
  73. /*
  74. * sst_get_sfreq - this function returns the frequency of the stream
  75. *
  76. * @str_param : stream params
  77. */
  78. int sst_get_sfreq(struct snd_sst_params *str_param)
  79. {
  80. switch (str_param->codec) {
  81. case SST_CODEC_TYPE_PCM:
  82. return str_param->sparams.uc.pcm_params.sfreq;
  83. case SST_CODEC_TYPE_AAC:
  84. return str_param->sparams.uc.aac_params.externalsr;
  85. case SST_CODEC_TYPE_MP3:
  86. return 0;
  87. default:
  88. return -EINVAL;
  89. }
  90. }
  91. /*
  92. * sst_get_num_channel - get number of channels for the stream
  93. *
  94. * @str_param : stream params
  95. */
  96. int sst_get_num_channel(struct snd_sst_params *str_param)
  97. {
  98. switch (str_param->codec) {
  99. case SST_CODEC_TYPE_PCM:
  100. return str_param->sparams.uc.pcm_params.num_chan;
  101. case SST_CODEC_TYPE_MP3:
  102. return str_param->sparams.uc.mp3_params.num_chan;
  103. case SST_CODEC_TYPE_AAC:
  104. return str_param->sparams.uc.aac_params.num_chan;
  105. default:
  106. return -EINVAL;
  107. }
  108. }
  109. /*
  110. * sst_get_stream - this function prepares for stream allocation
  111. *
  112. * @str_param : stream param
  113. */
  114. int sst_get_stream(struct intel_sst_drv *ctx,
  115. struct snd_sst_params *str_param)
  116. {
  117. int retval;
  118. struct stream_info *str_info;
  119. /* stream is not allocated, we are allocating */
  120. retval = ctx->ops->alloc_stream(ctx, str_param);
  121. if (retval <= 0) {
  122. return -EIO;
  123. }
  124. /* store sampling freq */
  125. str_info = &ctx->streams[retval];
  126. str_info->sfreq = sst_get_sfreq(str_param);
  127. return retval;
  128. }
  129. static int sst_power_control(struct device *dev, bool state)
  130. {
  131. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  132. int ret = 0;
  133. int usage_count = 0;
  134. if (state == true) {
  135. ret = pm_runtime_get_sync(dev);
  136. usage_count = GET_USAGE_COUNT(dev);
  137. dev_dbg(ctx->dev, "Enable: pm usage count: %d\n", usage_count);
  138. if (ret < 0) {
  139. pm_runtime_put_sync(dev);
  140. dev_err(ctx->dev, "Runtime get failed with err: %d\n", ret);
  141. return ret;
  142. }
  143. if ((ctx->sst_state == SST_RESET) && (usage_count == 1)) {
  144. ret = sst_load_fw(ctx);
  145. if (ret) {
  146. dev_err(dev, "FW download fail %d\n", ret);
  147. sst_set_fw_state_locked(ctx, SST_RESET);
  148. ret = sst_pm_runtime_put(ctx);
  149. }
  150. }
  151. } else {
  152. usage_count = GET_USAGE_COUNT(dev);
  153. dev_dbg(ctx->dev, "Disable: pm usage count: %d\n", usage_count);
  154. return sst_pm_runtime_put(ctx);
  155. }
  156. return ret;
  157. }
  158. /*
  159. * sst_open_pcm_stream - Open PCM interface
  160. *
  161. * @str_param: parameters of pcm stream
  162. *
  163. * This function is called by MID sound card driver to open
  164. * a new pcm interface
  165. */
  166. static int sst_open_pcm_stream(struct device *dev,
  167. struct snd_sst_params *str_param)
  168. {
  169. int retval;
  170. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  171. if (!str_param)
  172. return -EINVAL;
  173. retval = sst_get_stream(ctx, str_param);
  174. if (retval > 0)
  175. ctx->stream_cnt++;
  176. else
  177. dev_err(ctx->dev, "sst_get_stream returned err %d\n", retval);
  178. return retval;
  179. }
  180. static int sst_cdev_open(struct device *dev,
  181. struct snd_sst_params *str_params, struct sst_compress_cb *cb)
  182. {
  183. int str_id, retval;
  184. struct stream_info *stream;
  185. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  186. retval = pm_runtime_get_sync(ctx->dev);
  187. if (retval < 0) {
  188. pm_runtime_put_sync(ctx->dev);
  189. return retval;
  190. }
  191. str_id = sst_get_stream(ctx, str_params);
  192. if (str_id > 0) {
  193. dev_dbg(dev, "stream allocated in sst_cdev_open %d\n", str_id);
  194. stream = &ctx->streams[str_id];
  195. stream->compr_cb = cb->compr_cb;
  196. stream->compr_cb_param = cb->param;
  197. stream->drain_notify = cb->drain_notify;
  198. stream->drain_cb_param = cb->drain_cb_param;
  199. } else {
  200. dev_err(dev, "stream encountered error during alloc %d\n", str_id);
  201. str_id = -EINVAL;
  202. sst_pm_runtime_put(ctx);
  203. }
  204. return str_id;
  205. }
  206. static int sst_cdev_close(struct device *dev, unsigned int str_id)
  207. {
  208. int retval;
  209. struct stream_info *stream;
  210. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  211. stream = get_stream_info(ctx, str_id);
  212. if (!stream) {
  213. dev_err(dev, "stream info is NULL for str %d!!!\n", str_id);
  214. return -EINVAL;
  215. }
  216. retval = sst_free_stream(ctx, str_id);
  217. stream->compr_cb_param = NULL;
  218. stream->compr_cb = NULL;
  219. if (retval)
  220. dev_err(dev, "free stream returned err %d\n", retval);
  221. dev_dbg(dev, "End\n");
  222. return retval;
  223. }
  224. static int sst_cdev_ack(struct device *dev, unsigned int str_id,
  225. unsigned long bytes)
  226. {
  227. struct stream_info *stream;
  228. struct snd_sst_tstamp fw_tstamp = {0,};
  229. int offset;
  230. void __iomem *addr;
  231. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  232. stream = get_stream_info(ctx, str_id);
  233. if (!stream)
  234. return -EINVAL;
  235. /* update bytes sent */
  236. stream->cumm_bytes += bytes;
  237. dev_dbg(dev, "bytes copied %d inc by %ld\n", stream->cumm_bytes, bytes);
  238. addr = ((void __iomem *)(ctx->mailbox + ctx->tstamp)) +
  239. (str_id * sizeof(fw_tstamp));
  240. memcpy_fromio(&fw_tstamp, addr, sizeof(fw_tstamp));
  241. fw_tstamp.bytes_copied = stream->cumm_bytes;
  242. dev_dbg(dev, "bytes sent to fw %llu inc by %ld\n",
  243. fw_tstamp.bytes_copied, bytes);
  244. offset = offsetof(struct snd_sst_tstamp, bytes_copied);
  245. sst_shim_write(addr, offset, fw_tstamp.bytes_copied);
  246. return 0;
  247. }
  248. static int sst_cdev_set_metadata(struct device *dev,
  249. unsigned int str_id, struct snd_compr_metadata *metadata)
  250. {
  251. int retval = 0;
  252. struct stream_info *str_info;
  253. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  254. dev_dbg(dev, "set metadata for stream %d\n", str_id);
  255. str_info = get_stream_info(ctx, str_id);
  256. if (!str_info)
  257. return -EINVAL;
  258. dev_dbg(dev, "pipe id = %d\n", str_info->pipe_id);
  259. retval = sst_prepare_and_post_msg(ctx, str_info->task_id, IPC_CMD,
  260. IPC_IA_SET_STREAM_PARAMS_MRFLD, str_info->pipe_id,
  261. sizeof(*metadata), metadata, NULL,
  262. true, true, true, false);
  263. return retval;
  264. }
  265. static int sst_cdev_stream_pause(struct device *dev, unsigned int str_id)
  266. {
  267. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  268. return sst_pause_stream(ctx, str_id);
  269. }
  270. static int sst_cdev_stream_pause_release(struct device *dev,
  271. unsigned int str_id)
  272. {
  273. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  274. return sst_resume_stream(ctx, str_id);
  275. }
  276. static int sst_cdev_stream_start(struct device *dev, unsigned int str_id)
  277. {
  278. struct stream_info *str_info;
  279. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  280. str_info = get_stream_info(ctx, str_id);
  281. if (!str_info)
  282. return -EINVAL;
  283. str_info->prev = str_info->status;
  284. str_info->status = STREAM_RUNNING;
  285. return sst_start_stream(ctx, str_id);
  286. }
  287. static int sst_cdev_stream_drop(struct device *dev, unsigned int str_id)
  288. {
  289. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  290. return sst_drop_stream(ctx, str_id);
  291. }
  292. static int sst_cdev_stream_drain(struct device *dev, unsigned int str_id)
  293. {
  294. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  295. return sst_drain_stream(ctx, str_id, false);
  296. }
  297. static int sst_cdev_stream_partial_drain(struct device *dev,
  298. unsigned int str_id)
  299. {
  300. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  301. return sst_drain_stream(ctx, str_id, true);
  302. }
  303. static int sst_cdev_tstamp(struct device *dev, unsigned int str_id,
  304. struct snd_compr_tstamp *tstamp)
  305. {
  306. struct snd_sst_tstamp fw_tstamp = {0,};
  307. struct stream_info *stream;
  308. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  309. void __iomem *addr;
  310. addr = (void __iomem *)(ctx->mailbox + ctx->tstamp) +
  311. (str_id * sizeof(fw_tstamp));
  312. memcpy_fromio(&fw_tstamp, addr, sizeof(fw_tstamp));
  313. stream = get_stream_info(ctx, str_id);
  314. if (!stream)
  315. return -EINVAL;
  316. dev_dbg(dev, "rb_counter %llu in bytes\n", fw_tstamp.ring_buffer_counter);
  317. tstamp->copied_total = fw_tstamp.ring_buffer_counter;
  318. tstamp->pcm_frames = fw_tstamp.frames_decoded;
  319. tstamp->pcm_io_frames = div_u64(fw_tstamp.hardware_counter,
  320. (u64)stream->num_ch * SST_GET_BYTES_PER_SAMPLE(24));
  321. tstamp->sampling_rate = fw_tstamp.sampling_frequency;
  322. dev_dbg(dev, "PCM = %u\n", tstamp->pcm_io_frames);
  323. dev_dbg(dev, "Ptr Query on strid = %d copied_total %d, decodec %d\n",
  324. str_id, tstamp->copied_total, tstamp->pcm_frames);
  325. dev_dbg(dev, "rendered %d\n", tstamp->pcm_io_frames);
  326. return 0;
  327. }
  328. static int sst_cdev_caps(struct snd_compr_caps *caps)
  329. {
  330. caps->num_codecs = NUM_CODEC;
  331. caps->min_fragment_size = MIN_FRAGMENT_SIZE; /* 50KB */
  332. caps->max_fragment_size = MAX_FRAGMENT_SIZE; /* 1024KB */
  333. caps->min_fragments = MIN_FRAGMENT;
  334. caps->max_fragments = MAX_FRAGMENT;
  335. caps->codecs[0] = SND_AUDIOCODEC_MP3;
  336. caps->codecs[1] = SND_AUDIOCODEC_AAC;
  337. return 0;
  338. }
  339. static const struct snd_compr_codec_caps caps_mp3 = {
  340. .num_descriptors = 1,
  341. .descriptor[0].max_ch = 2,
  342. .descriptor[0].sample_rates[0] = 48000,
  343. .descriptor[0].sample_rates[1] = 44100,
  344. .descriptor[0].sample_rates[2] = 32000,
  345. .descriptor[0].sample_rates[3] = 16000,
  346. .descriptor[0].sample_rates[4] = 8000,
  347. .descriptor[0].num_sample_rates = 5,
  348. .descriptor[0].bit_rate[0] = 320,
  349. .descriptor[0].bit_rate[1] = 192,
  350. .descriptor[0].num_bitrates = 2,
  351. .descriptor[0].profiles = 0,
  352. .descriptor[0].modes = SND_AUDIOCHANMODE_MP3_STEREO,
  353. .descriptor[0].formats = 0,
  354. };
  355. static const struct snd_compr_codec_caps caps_aac = {
  356. .num_descriptors = 2,
  357. .descriptor[1].max_ch = 2,
  358. .descriptor[0].sample_rates[0] = 48000,
  359. .descriptor[0].sample_rates[1] = 44100,
  360. .descriptor[0].sample_rates[2] = 32000,
  361. .descriptor[0].sample_rates[3] = 16000,
  362. .descriptor[0].sample_rates[4] = 8000,
  363. .descriptor[0].num_sample_rates = 5,
  364. .descriptor[1].bit_rate[0] = 320,
  365. .descriptor[1].bit_rate[1] = 192,
  366. .descriptor[1].num_bitrates = 2,
  367. .descriptor[1].profiles = 0,
  368. .descriptor[1].modes = 0,
  369. .descriptor[1].formats =
  370. (SND_AUDIOSTREAMFORMAT_MP4ADTS |
  371. SND_AUDIOSTREAMFORMAT_RAW),
  372. };
  373. static int sst_cdev_codec_caps(struct snd_compr_codec_caps *codec)
  374. {
  375. if (codec->codec == SND_AUDIOCODEC_MP3)
  376. *codec = caps_mp3;
  377. else if (codec->codec == SND_AUDIOCODEC_AAC)
  378. *codec = caps_aac;
  379. else
  380. return -EINVAL;
  381. return 0;
  382. }
  383. void sst_cdev_fragment_elapsed(struct intel_sst_drv *ctx, int str_id)
  384. {
  385. struct stream_info *stream;
  386. dev_dbg(ctx->dev, "fragment elapsed from firmware for str_id %d\n",
  387. str_id);
  388. stream = &ctx->streams[str_id];
  389. if (stream->compr_cb)
  390. stream->compr_cb(stream->compr_cb_param);
  391. }
  392. /*
  393. * sst_close_pcm_stream - Close PCM interface
  394. *
  395. * @str_id: stream id to be closed
  396. *
  397. * This function is called by MID sound card driver to close
  398. * an existing pcm interface
  399. */
  400. static int sst_close_pcm_stream(struct device *dev, unsigned int str_id)
  401. {
  402. struct stream_info *stream;
  403. int retval = 0;
  404. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  405. stream = get_stream_info(ctx, str_id);
  406. if (!stream) {
  407. dev_err(ctx->dev, "stream info is NULL for str %d!!!\n", str_id);
  408. return -EINVAL;
  409. }
  410. retval = free_stream_context(ctx, str_id);
  411. stream->pcm_substream = NULL;
  412. stream->status = STREAM_UN_INIT;
  413. stream->period_elapsed = NULL;
  414. ctx->stream_cnt--;
  415. if (retval)
  416. dev_err(ctx->dev, "free stream returned err %d\n", retval);
  417. dev_dbg(ctx->dev, "Exit\n");
  418. return 0;
  419. }
  420. static inline int sst_calc_tstamp(struct intel_sst_drv *ctx,
  421. struct pcm_stream_info *info,
  422. struct snd_pcm_substream *substream,
  423. struct snd_sst_tstamp *fw_tstamp)
  424. {
  425. size_t delay_bytes, delay_frames;
  426. size_t buffer_sz;
  427. u32 pointer_bytes, pointer_samples;
  428. dev_dbg(ctx->dev, "mrfld ring_buffer_counter %llu in bytes\n",
  429. fw_tstamp->ring_buffer_counter);
  430. dev_dbg(ctx->dev, "mrfld hardware_counter %llu in bytes\n",
  431. fw_tstamp->hardware_counter);
  432. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  433. delay_bytes = (size_t) (fw_tstamp->ring_buffer_counter -
  434. fw_tstamp->hardware_counter);
  435. else
  436. delay_bytes = (size_t) (fw_tstamp->hardware_counter -
  437. fw_tstamp->ring_buffer_counter);
  438. delay_frames = bytes_to_frames(substream->runtime, delay_bytes);
  439. buffer_sz = snd_pcm_lib_buffer_bytes(substream);
  440. div_u64_rem(fw_tstamp->ring_buffer_counter, buffer_sz, &pointer_bytes);
  441. pointer_samples = bytes_to_samples(substream->runtime, pointer_bytes);
  442. dev_dbg(ctx->dev, "pcm delay %zu in bytes\n", delay_bytes);
  443. info->buffer_ptr = pointer_samples / substream->runtime->channels;
  444. info->pcm_delay = delay_frames;
  445. dev_dbg(ctx->dev, "buffer ptr %llu pcm_delay rep: %llu\n",
  446. info->buffer_ptr, info->pcm_delay);
  447. return 0;
  448. }
  449. static int sst_read_timestamp(struct device *dev, struct pcm_stream_info *info)
  450. {
  451. struct stream_info *stream;
  452. struct snd_pcm_substream *substream;
  453. struct snd_sst_tstamp fw_tstamp;
  454. unsigned int str_id;
  455. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  456. void __iomem *addr;
  457. str_id = info->str_id;
  458. stream = get_stream_info(ctx, str_id);
  459. if (!stream)
  460. return -EINVAL;
  461. if (!stream->pcm_substream)
  462. return -EINVAL;
  463. substream = stream->pcm_substream;
  464. addr = (void __iomem *)(ctx->mailbox + ctx->tstamp) +
  465. (str_id * sizeof(fw_tstamp));
  466. memcpy_fromio(&fw_tstamp, addr, sizeof(fw_tstamp));
  467. return sst_calc_tstamp(ctx, info, substream, &fw_tstamp);
  468. }
  469. static int sst_stream_start(struct device *dev, int str_id)
  470. {
  471. struct stream_info *str_info;
  472. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  473. if (ctx->sst_state != SST_FW_RUNNING)
  474. return 0;
  475. str_info = get_stream_info(ctx, str_id);
  476. if (!str_info)
  477. return -EINVAL;
  478. str_info->prev = str_info->status;
  479. str_info->status = STREAM_RUNNING;
  480. sst_start_stream(ctx, str_id);
  481. return 0;
  482. }
  483. static int sst_stream_drop(struct device *dev, int str_id)
  484. {
  485. struct stream_info *str_info;
  486. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  487. if (ctx->sst_state != SST_FW_RUNNING)
  488. return 0;
  489. str_info = get_stream_info(ctx, str_id);
  490. if (!str_info)
  491. return -EINVAL;
  492. str_info->prev = STREAM_UN_INIT;
  493. str_info->status = STREAM_INIT;
  494. return sst_drop_stream(ctx, str_id);
  495. }
  496. static int sst_stream_pause(struct device *dev, int str_id)
  497. {
  498. struct stream_info *str_info;
  499. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  500. if (ctx->sst_state != SST_FW_RUNNING)
  501. return 0;
  502. str_info = get_stream_info(ctx, str_id);
  503. if (!str_info)
  504. return -EINVAL;
  505. return sst_pause_stream(ctx, str_id);
  506. }
  507. static int sst_stream_resume(struct device *dev, int str_id)
  508. {
  509. struct stream_info *str_info;
  510. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  511. if (ctx->sst_state != SST_FW_RUNNING)
  512. return 0;
  513. str_info = get_stream_info(ctx, str_id);
  514. if (!str_info)
  515. return -EINVAL;
  516. return sst_resume_stream(ctx, str_id);
  517. }
  518. static int sst_stream_init(struct device *dev, struct pcm_stream_info *str_info)
  519. {
  520. int str_id = 0;
  521. struct stream_info *stream;
  522. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  523. str_id = str_info->str_id;
  524. if (ctx->sst_state != SST_FW_RUNNING)
  525. return 0;
  526. stream = get_stream_info(ctx, str_id);
  527. if (!stream)
  528. return -EINVAL;
  529. dev_dbg(ctx->dev, "setting the period ptrs\n");
  530. stream->pcm_substream = str_info->arg;
  531. stream->period_elapsed = str_info->period_elapsed;
  532. stream->sfreq = str_info->sfreq;
  533. stream->prev = stream->status;
  534. stream->status = STREAM_INIT;
  535. dev_dbg(ctx->dev,
  536. "pcm_substream %p, period_elapsed %p, sfreq %d, status %d\n",
  537. stream->pcm_substream, stream->period_elapsed,
  538. stream->sfreq, stream->status);
  539. return 0;
  540. }
  541. /*
  542. * sst_set_byte_stream - Set generic params
  543. *
  544. * @cmd: control cmd to be set
  545. * @arg: command argument
  546. *
  547. * This function is called by MID sound card driver to configure
  548. * SST runtime params.
  549. */
  550. static int sst_send_byte_stream(struct device *dev,
  551. struct snd_sst_bytes_v2 *bytes)
  552. {
  553. int ret_val = 0;
  554. struct intel_sst_drv *ctx = dev_get_drvdata(dev);
  555. if (NULL == bytes)
  556. return -EINVAL;
  557. ret_val = pm_runtime_get_sync(ctx->dev);
  558. if (ret_val < 0) {
  559. pm_runtime_put_sync(ctx->dev);
  560. return ret_val;
  561. }
  562. ret_val = sst_send_byte_stream_mrfld(ctx, bytes);
  563. sst_pm_runtime_put(ctx);
  564. return ret_val;
  565. }
  566. static struct sst_ops pcm_ops = {
  567. .open = sst_open_pcm_stream,
  568. .stream_init = sst_stream_init,
  569. .stream_start = sst_stream_start,
  570. .stream_drop = sst_stream_drop,
  571. .stream_pause = sst_stream_pause,
  572. .stream_pause_release = sst_stream_resume,
  573. .stream_read_tstamp = sst_read_timestamp,
  574. .send_byte_stream = sst_send_byte_stream,
  575. .close = sst_close_pcm_stream,
  576. .power = sst_power_control,
  577. };
  578. static struct compress_sst_ops compr_ops = {
  579. .open = sst_cdev_open,
  580. .close = sst_cdev_close,
  581. .stream_pause = sst_cdev_stream_pause,
  582. .stream_pause_release = sst_cdev_stream_pause_release,
  583. .stream_start = sst_cdev_stream_start,
  584. .stream_drop = sst_cdev_stream_drop,
  585. .stream_drain = sst_cdev_stream_drain,
  586. .stream_partial_drain = sst_cdev_stream_partial_drain,
  587. .tstamp = sst_cdev_tstamp,
  588. .ack = sst_cdev_ack,
  589. .get_caps = sst_cdev_caps,
  590. .get_codec_caps = sst_cdev_codec_caps,
  591. .set_metadata = sst_cdev_set_metadata,
  592. .power = sst_power_control,
  593. };
  594. static struct sst_device sst_dsp_device = {
  595. .name = "Intel(R) SST LPE",
  596. .dev = NULL,
  597. .ops = &pcm_ops,
  598. .compr_ops = &compr_ops,
  599. };
  600. /*
  601. * sst_register - function to register DSP
  602. *
  603. * This functions registers DSP with the platform driver
  604. */
  605. int sst_register(struct device *dev)
  606. {
  607. int ret_val;
  608. sst_dsp_device.dev = dev;
  609. ret_val = sst_register_dsp(&sst_dsp_device);
  610. if (ret_val)
  611. dev_err(dev, "Unable to register DSP with platform driver\n");
  612. return ret_val;
  613. }
  614. int sst_unregister(struct device *dev)
  615. {
  616. return sst_unregister_dsp(&sst_dsp_device);
  617. }