sst_platform.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. /*
  2. * sst_platform.c - Intel MID Platform driver
  3. *
  4. * Copyright (C) 2010-2012 Intel Corp
  5. * Author: Vinod Koul <vinod.koul@intel.com>
  6. * Author: Harsha Priya <priya.harsha@intel.com>
  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. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  21. *
  22. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. *
  24. *
  25. */
  26. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  27. #include <linux/slab.h>
  28. #include <linux/io.h>
  29. #include <linux/module.h>
  30. #include <sound/core.h>
  31. #include <sound/pcm.h>
  32. #include <sound/pcm_params.h>
  33. #include <sound/soc.h>
  34. #include <sound/compress_driver.h>
  35. #include "sst_platform.h"
  36. static struct sst_device *sst;
  37. static DEFINE_MUTEX(sst_lock);
  38. int sst_register_dsp(struct sst_device *dev)
  39. {
  40. BUG_ON(!dev);
  41. if (!try_module_get(dev->dev->driver->owner))
  42. return -ENODEV;
  43. mutex_lock(&sst_lock);
  44. if (sst) {
  45. pr_err("we already have a device %s\n", sst->name);
  46. module_put(dev->dev->driver->owner);
  47. mutex_unlock(&sst_lock);
  48. return -EEXIST;
  49. }
  50. pr_debug("registering device %s\n", dev->name);
  51. sst = dev;
  52. mutex_unlock(&sst_lock);
  53. return 0;
  54. }
  55. EXPORT_SYMBOL_GPL(sst_register_dsp);
  56. int sst_unregister_dsp(struct sst_device *dev)
  57. {
  58. BUG_ON(!dev);
  59. if (dev != sst)
  60. return -EINVAL;
  61. mutex_lock(&sst_lock);
  62. if (!sst) {
  63. mutex_unlock(&sst_lock);
  64. return -EIO;
  65. }
  66. module_put(sst->dev->driver->owner);
  67. pr_debug("unreg %s\n", sst->name);
  68. sst = NULL;
  69. mutex_unlock(&sst_lock);
  70. return 0;
  71. }
  72. EXPORT_SYMBOL_GPL(sst_unregister_dsp);
  73. static struct snd_pcm_hardware sst_platform_pcm_hw = {
  74. .info = (SNDRV_PCM_INFO_INTERLEAVED |
  75. SNDRV_PCM_INFO_DOUBLE |
  76. SNDRV_PCM_INFO_PAUSE |
  77. SNDRV_PCM_INFO_RESUME |
  78. SNDRV_PCM_INFO_MMAP|
  79. SNDRV_PCM_INFO_MMAP_VALID |
  80. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  81. SNDRV_PCM_INFO_SYNC_START),
  82. .formats = (SNDRV_PCM_FMTBIT_S16 | SNDRV_PCM_FMTBIT_U16 |
  83. SNDRV_PCM_FMTBIT_S24 | SNDRV_PCM_FMTBIT_U24 |
  84. SNDRV_PCM_FMTBIT_S32 | SNDRV_PCM_FMTBIT_U32),
  85. .rates = (SNDRV_PCM_RATE_8000|
  86. SNDRV_PCM_RATE_44100 |
  87. SNDRV_PCM_RATE_48000),
  88. .rate_min = SST_MIN_RATE,
  89. .rate_max = SST_MAX_RATE,
  90. .channels_min = SST_MIN_CHANNEL,
  91. .channels_max = SST_MAX_CHANNEL,
  92. .buffer_bytes_max = SST_MAX_BUFFER,
  93. .period_bytes_min = SST_MIN_PERIOD_BYTES,
  94. .period_bytes_max = SST_MAX_PERIOD_BYTES,
  95. .periods_min = SST_MIN_PERIODS,
  96. .periods_max = SST_MAX_PERIODS,
  97. .fifo_size = SST_FIFO_SIZE,
  98. };
  99. /* MFLD - MSIC */
  100. static struct snd_soc_dai_driver sst_platform_dai[] = {
  101. {
  102. .name = "Headset-cpu-dai",
  103. .id = 0,
  104. .playback = {
  105. .channels_min = SST_STEREO,
  106. .channels_max = SST_STEREO,
  107. .rates = SNDRV_PCM_RATE_48000,
  108. .formats = SNDRV_PCM_FMTBIT_S24_LE,
  109. },
  110. .capture = {
  111. .channels_min = 1,
  112. .channels_max = 5,
  113. .rates = SNDRV_PCM_RATE_48000,
  114. .formats = SNDRV_PCM_FMTBIT_S24_LE,
  115. },
  116. },
  117. {
  118. .name = "Speaker-cpu-dai",
  119. .id = 1,
  120. .playback = {
  121. .channels_min = SST_MONO,
  122. .channels_max = SST_STEREO,
  123. .rates = SNDRV_PCM_RATE_48000,
  124. .formats = SNDRV_PCM_FMTBIT_S24_LE,
  125. },
  126. },
  127. {
  128. .name = "Vibra1-cpu-dai",
  129. .id = 2,
  130. .playback = {
  131. .channels_min = SST_MONO,
  132. .channels_max = SST_MONO,
  133. .rates = SNDRV_PCM_RATE_48000,
  134. .formats = SNDRV_PCM_FMTBIT_S24_LE,
  135. },
  136. },
  137. {
  138. .name = "Vibra2-cpu-dai",
  139. .id = 3,
  140. .playback = {
  141. .channels_min = SST_MONO,
  142. .channels_max = SST_STEREO,
  143. .rates = SNDRV_PCM_RATE_48000,
  144. .formats = SNDRV_PCM_FMTBIT_S24_LE,
  145. },
  146. },
  147. {
  148. .name = "Compress-cpu-dai",
  149. .compress_dai = 1,
  150. .playback = {
  151. .channels_min = SST_STEREO,
  152. .channels_max = SST_STEREO,
  153. .rates = SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000,
  154. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  155. },
  156. },
  157. };
  158. /* helper functions */
  159. static inline void sst_set_stream_status(struct sst_runtime_stream *stream,
  160. int state)
  161. {
  162. unsigned long flags;
  163. spin_lock_irqsave(&stream->status_lock, flags);
  164. stream->stream_status = state;
  165. spin_unlock_irqrestore(&stream->status_lock, flags);
  166. }
  167. static inline int sst_get_stream_status(struct sst_runtime_stream *stream)
  168. {
  169. int state;
  170. unsigned long flags;
  171. spin_lock_irqsave(&stream->status_lock, flags);
  172. state = stream->stream_status;
  173. spin_unlock_irqrestore(&stream->status_lock, flags);
  174. return state;
  175. }
  176. static void sst_fill_pcm_params(struct snd_pcm_substream *substream,
  177. struct sst_pcm_params *param)
  178. {
  179. param->codec = SST_CODEC_TYPE_PCM;
  180. param->num_chan = (u8) substream->runtime->channels;
  181. param->pcm_wd_sz = substream->runtime->sample_bits;
  182. param->reserved = 0;
  183. param->sfreq = substream->runtime->rate;
  184. param->ring_buffer_size = snd_pcm_lib_buffer_bytes(substream);
  185. param->period_count = substream->runtime->period_size;
  186. param->ring_buffer_addr = virt_to_phys(substream->dma_buffer.area);
  187. pr_debug("period_cnt = %d\n", param->period_count);
  188. pr_debug("sfreq= %d, wd_sz = %d\n", param->sfreq, param->pcm_wd_sz);
  189. }
  190. static int sst_platform_alloc_stream(struct snd_pcm_substream *substream)
  191. {
  192. struct sst_runtime_stream *stream =
  193. substream->runtime->private_data;
  194. struct sst_pcm_params param = {0};
  195. struct sst_stream_params str_params = {0};
  196. int ret_val;
  197. /* set codec params and inform SST driver the same */
  198. sst_fill_pcm_params(substream, &param);
  199. substream->runtime->dma_area = substream->dma_buffer.area;
  200. str_params.sparams = param;
  201. str_params.codec = param.codec;
  202. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  203. str_params.ops = STREAM_OPS_PLAYBACK;
  204. str_params.device_type = substream->pcm->device + 1;
  205. pr_debug("Playbck stream,Device %d\n",
  206. substream->pcm->device);
  207. } else {
  208. str_params.ops = STREAM_OPS_CAPTURE;
  209. str_params.device_type = SND_SST_DEVICE_CAPTURE;
  210. pr_debug("Capture stream,Device %d\n",
  211. substream->pcm->device);
  212. }
  213. ret_val = stream->ops->open(&str_params);
  214. pr_debug("SST_SND_PLAY/CAPTURE ret_val = %x\n", ret_val);
  215. if (ret_val < 0)
  216. return ret_val;
  217. stream->stream_info.str_id = ret_val;
  218. pr_debug("str id : %d\n", stream->stream_info.str_id);
  219. return ret_val;
  220. }
  221. static void sst_period_elapsed(void *mad_substream)
  222. {
  223. struct snd_pcm_substream *substream = mad_substream;
  224. struct sst_runtime_stream *stream;
  225. int status;
  226. if (!substream || !substream->runtime)
  227. return;
  228. stream = substream->runtime->private_data;
  229. if (!stream)
  230. return;
  231. status = sst_get_stream_status(stream);
  232. if (status != SST_PLATFORM_RUNNING)
  233. return;
  234. snd_pcm_period_elapsed(substream);
  235. }
  236. static int sst_platform_init_stream(struct snd_pcm_substream *substream)
  237. {
  238. struct sst_runtime_stream *stream =
  239. substream->runtime->private_data;
  240. int ret_val;
  241. pr_debug("setting buffer ptr param\n");
  242. sst_set_stream_status(stream, SST_PLATFORM_INIT);
  243. stream->stream_info.period_elapsed = sst_period_elapsed;
  244. stream->stream_info.mad_substream = substream;
  245. stream->stream_info.buffer_ptr = 0;
  246. stream->stream_info.sfreq = substream->runtime->rate;
  247. ret_val = stream->ops->device_control(
  248. SST_SND_STREAM_INIT, &stream->stream_info);
  249. if (ret_val)
  250. pr_err("control_set ret error %d\n", ret_val);
  251. return ret_val;
  252. }
  253. /* end -- helper functions */
  254. static int sst_platform_open(struct snd_pcm_substream *substream)
  255. {
  256. struct snd_pcm_runtime *runtime = substream->runtime;
  257. struct sst_runtime_stream *stream;
  258. int ret_val;
  259. pr_debug("sst_platform_open called\n");
  260. snd_soc_set_runtime_hwparams(substream, &sst_platform_pcm_hw);
  261. ret_val = snd_pcm_hw_constraint_integer(runtime,
  262. SNDRV_PCM_HW_PARAM_PERIODS);
  263. if (ret_val < 0)
  264. return ret_val;
  265. stream = kzalloc(sizeof(*stream), GFP_KERNEL);
  266. if (!stream)
  267. return -ENOMEM;
  268. spin_lock_init(&stream->status_lock);
  269. /* get the sst ops */
  270. mutex_lock(&sst_lock);
  271. if (!sst) {
  272. pr_err("no device available to run\n");
  273. mutex_unlock(&sst_lock);
  274. kfree(stream);
  275. return -ENODEV;
  276. }
  277. if (!try_module_get(sst->dev->driver->owner)) {
  278. mutex_unlock(&sst_lock);
  279. kfree(stream);
  280. return -ENODEV;
  281. }
  282. stream->ops = sst->ops;
  283. mutex_unlock(&sst_lock);
  284. stream->stream_info.str_id = 0;
  285. sst_set_stream_status(stream, SST_PLATFORM_INIT);
  286. stream->stream_info.mad_substream = substream;
  287. /* allocate memory for SST API set */
  288. runtime->private_data = stream;
  289. return 0;
  290. }
  291. static int sst_platform_close(struct snd_pcm_substream *substream)
  292. {
  293. struct sst_runtime_stream *stream;
  294. int ret_val = 0, str_id;
  295. pr_debug("sst_platform_close called\n");
  296. stream = substream->runtime->private_data;
  297. str_id = stream->stream_info.str_id;
  298. if (str_id)
  299. ret_val = stream->ops->close(str_id);
  300. module_put(sst->dev->driver->owner);
  301. kfree(stream);
  302. return ret_val;
  303. }
  304. static int sst_platform_pcm_prepare(struct snd_pcm_substream *substream)
  305. {
  306. struct sst_runtime_stream *stream;
  307. int ret_val = 0, str_id;
  308. pr_debug("sst_platform_pcm_prepare called\n");
  309. stream = substream->runtime->private_data;
  310. str_id = stream->stream_info.str_id;
  311. if (stream->stream_info.str_id) {
  312. ret_val = stream->ops->device_control(
  313. SST_SND_DROP, &str_id);
  314. return ret_val;
  315. }
  316. ret_val = sst_platform_alloc_stream(substream);
  317. if (ret_val < 0)
  318. return ret_val;
  319. snprintf(substream->pcm->id, sizeof(substream->pcm->id),
  320. "%d", stream->stream_info.str_id);
  321. ret_val = sst_platform_init_stream(substream);
  322. if (ret_val)
  323. return ret_val;
  324. substream->runtime->hw.info = SNDRV_PCM_INFO_BLOCK_TRANSFER;
  325. return ret_val;
  326. }
  327. static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream,
  328. int cmd)
  329. {
  330. int ret_val = 0, str_id;
  331. struct sst_runtime_stream *stream;
  332. int str_cmd, status;
  333. pr_debug("sst_platform_pcm_trigger called\n");
  334. stream = substream->runtime->private_data;
  335. str_id = stream->stream_info.str_id;
  336. switch (cmd) {
  337. case SNDRV_PCM_TRIGGER_START:
  338. pr_debug("sst: Trigger Start\n");
  339. str_cmd = SST_SND_START;
  340. status = SST_PLATFORM_RUNNING;
  341. stream->stream_info.mad_substream = substream;
  342. break;
  343. case SNDRV_PCM_TRIGGER_STOP:
  344. pr_debug("sst: in stop\n");
  345. str_cmd = SST_SND_DROP;
  346. status = SST_PLATFORM_DROPPED;
  347. break;
  348. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  349. pr_debug("sst: in pause\n");
  350. str_cmd = SST_SND_PAUSE;
  351. status = SST_PLATFORM_PAUSED;
  352. break;
  353. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  354. pr_debug("sst: in pause release\n");
  355. str_cmd = SST_SND_RESUME;
  356. status = SST_PLATFORM_RUNNING;
  357. break;
  358. default:
  359. return -EINVAL;
  360. }
  361. ret_val = stream->ops->device_control(str_cmd, &str_id);
  362. if (!ret_val)
  363. sst_set_stream_status(stream, status);
  364. return ret_val;
  365. }
  366. static snd_pcm_uframes_t sst_platform_pcm_pointer
  367. (struct snd_pcm_substream *substream)
  368. {
  369. struct sst_runtime_stream *stream;
  370. int ret_val, status;
  371. struct pcm_stream_info *str_info;
  372. stream = substream->runtime->private_data;
  373. status = sst_get_stream_status(stream);
  374. if (status == SST_PLATFORM_INIT)
  375. return 0;
  376. str_info = &stream->stream_info;
  377. ret_val = stream->ops->device_control(
  378. SST_SND_BUFFER_POINTER, str_info);
  379. if (ret_val) {
  380. pr_err("sst: error code = %d\n", ret_val);
  381. return ret_val;
  382. }
  383. return stream->stream_info.buffer_ptr;
  384. }
  385. static int sst_platform_pcm_hw_params(struct snd_pcm_substream *substream,
  386. struct snd_pcm_hw_params *params)
  387. {
  388. snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  389. memset(substream->runtime->dma_area, 0, params_buffer_bytes(params));
  390. return 0;
  391. }
  392. static int sst_platform_pcm_hw_free(struct snd_pcm_substream *substream)
  393. {
  394. return snd_pcm_lib_free_pages(substream);
  395. }
  396. static struct snd_pcm_ops sst_platform_ops = {
  397. .open = sst_platform_open,
  398. .close = sst_platform_close,
  399. .ioctl = snd_pcm_lib_ioctl,
  400. .prepare = sst_platform_pcm_prepare,
  401. .trigger = sst_platform_pcm_trigger,
  402. .pointer = sst_platform_pcm_pointer,
  403. .hw_params = sst_platform_pcm_hw_params,
  404. .hw_free = sst_platform_pcm_hw_free,
  405. };
  406. static void sst_pcm_free(struct snd_pcm *pcm)
  407. {
  408. pr_debug("sst_pcm_free called\n");
  409. snd_pcm_lib_preallocate_free_for_all(pcm);
  410. }
  411. static int sst_pcm_new(struct snd_soc_pcm_runtime *rtd)
  412. {
  413. struct snd_pcm *pcm = rtd->pcm;
  414. int retval = 0;
  415. pr_debug("sst_pcm_new called\n");
  416. if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream ||
  417. pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
  418. retval = snd_pcm_lib_preallocate_pages_for_all(pcm,
  419. SNDRV_DMA_TYPE_CONTINUOUS,
  420. snd_dma_continuous_data(GFP_KERNEL),
  421. SST_MIN_BUFFER, SST_MAX_BUFFER);
  422. if (retval) {
  423. pr_err("dma buffer allocationf fail\n");
  424. return retval;
  425. }
  426. }
  427. return retval;
  428. }
  429. /* compress stream operations */
  430. static void sst_compr_fragment_elapsed(void *arg)
  431. {
  432. struct snd_compr_stream *cstream = (struct snd_compr_stream *)arg;
  433. pr_debug("fragment elapsed by driver\n");
  434. if (cstream)
  435. snd_compr_fragment_elapsed(cstream);
  436. }
  437. static int sst_platform_compr_open(struct snd_compr_stream *cstream)
  438. {
  439. int ret_val = 0;
  440. struct snd_compr_runtime *runtime = cstream->runtime;
  441. struct sst_runtime_stream *stream;
  442. stream = kzalloc(sizeof(*stream), GFP_KERNEL);
  443. if (!stream)
  444. return -ENOMEM;
  445. spin_lock_init(&stream->status_lock);
  446. /* get the sst ops */
  447. if (!sst || !try_module_get(sst->dev->driver->owner)) {
  448. pr_err("no device available to run\n");
  449. ret_val = -ENODEV;
  450. goto out_ops;
  451. }
  452. stream->compr_ops = sst->compr_ops;
  453. stream->id = 0;
  454. sst_set_stream_status(stream, SST_PLATFORM_INIT);
  455. runtime->private_data = stream;
  456. return 0;
  457. out_ops:
  458. kfree(stream);
  459. return ret_val;
  460. }
  461. static int sst_platform_compr_free(struct snd_compr_stream *cstream)
  462. {
  463. struct sst_runtime_stream *stream;
  464. int ret_val = 0, str_id;
  465. stream = cstream->runtime->private_data;
  466. /*need to check*/
  467. str_id = stream->id;
  468. if (str_id)
  469. ret_val = stream->compr_ops->close(str_id);
  470. module_put(sst->dev->driver->owner);
  471. kfree(stream);
  472. pr_debug("%s: %d\n", __func__, ret_val);
  473. return 0;
  474. }
  475. static int sst_platform_compr_set_params(struct snd_compr_stream *cstream,
  476. struct snd_compr_params *params)
  477. {
  478. struct sst_runtime_stream *stream;
  479. int retval;
  480. struct snd_sst_params str_params;
  481. struct sst_compress_cb cb;
  482. stream = cstream->runtime->private_data;
  483. /* construct fw structure for this*/
  484. memset(&str_params, 0, sizeof(str_params));
  485. str_params.ops = STREAM_OPS_PLAYBACK;
  486. str_params.stream_type = SST_STREAM_TYPE_MUSIC;
  487. str_params.device_type = SND_SST_DEVICE_COMPRESS;
  488. switch (params->codec.id) {
  489. case SND_AUDIOCODEC_MP3: {
  490. str_params.codec = SST_CODEC_TYPE_MP3;
  491. str_params.sparams.uc.mp3_params.codec = SST_CODEC_TYPE_MP3;
  492. str_params.sparams.uc.mp3_params.num_chan = params->codec.ch_in;
  493. str_params.sparams.uc.mp3_params.pcm_wd_sz = 16;
  494. break;
  495. }
  496. case SND_AUDIOCODEC_AAC: {
  497. str_params.codec = SST_CODEC_TYPE_AAC;
  498. str_params.sparams.uc.aac_params.codec = SST_CODEC_TYPE_AAC;
  499. str_params.sparams.uc.aac_params.num_chan = params->codec.ch_in;
  500. str_params.sparams.uc.aac_params.pcm_wd_sz = 16;
  501. if (params->codec.format == SND_AUDIOSTREAMFORMAT_MP4ADTS)
  502. str_params.sparams.uc.aac_params.bs_format =
  503. AAC_BIT_STREAM_ADTS;
  504. else if (params->codec.format == SND_AUDIOSTREAMFORMAT_RAW)
  505. str_params.sparams.uc.aac_params.bs_format =
  506. AAC_BIT_STREAM_RAW;
  507. else {
  508. pr_err("Undefined format%d\n", params->codec.format);
  509. return -EINVAL;
  510. }
  511. str_params.sparams.uc.aac_params.externalsr =
  512. params->codec.sample_rate;
  513. break;
  514. }
  515. default:
  516. pr_err("codec not supported, id =%d\n", params->codec.id);
  517. return -EINVAL;
  518. }
  519. str_params.aparams.ring_buf_info[0].addr =
  520. virt_to_phys(cstream->runtime->buffer);
  521. str_params.aparams.ring_buf_info[0].size =
  522. cstream->runtime->buffer_size;
  523. str_params.aparams.sg_count = 1;
  524. str_params.aparams.frag_size = cstream->runtime->fragment_size;
  525. cb.param = cstream;
  526. cb.compr_cb = sst_compr_fragment_elapsed;
  527. retval = stream->compr_ops->open(&str_params, &cb);
  528. if (retval < 0) {
  529. pr_err("stream allocation failed %d\n", retval);
  530. return retval;
  531. }
  532. stream->id = retval;
  533. return 0;
  534. }
  535. static int sst_platform_compr_trigger(struct snd_compr_stream *cstream, int cmd)
  536. {
  537. struct sst_runtime_stream *stream =
  538. cstream->runtime->private_data;
  539. return stream->compr_ops->control(cmd, stream->id);
  540. }
  541. static int sst_platform_compr_pointer(struct snd_compr_stream *cstream,
  542. struct snd_compr_tstamp *tstamp)
  543. {
  544. struct sst_runtime_stream *stream;
  545. stream = cstream->runtime->private_data;
  546. stream->compr_ops->tstamp(stream->id, tstamp);
  547. tstamp->byte_offset = tstamp->copied_total %
  548. (u32)cstream->runtime->buffer_size;
  549. pr_debug("calc bytes offset/copied bytes as %d\n", tstamp->byte_offset);
  550. return 0;
  551. }
  552. static int sst_platform_compr_ack(struct snd_compr_stream *cstream,
  553. size_t bytes)
  554. {
  555. struct sst_runtime_stream *stream;
  556. stream = cstream->runtime->private_data;
  557. stream->compr_ops->ack(stream->id, (unsigned long)bytes);
  558. stream->bytes_written += bytes;
  559. return 0;
  560. }
  561. static int sst_platform_compr_get_caps(struct snd_compr_stream *cstream,
  562. struct snd_compr_caps *caps)
  563. {
  564. struct sst_runtime_stream *stream =
  565. cstream->runtime->private_data;
  566. return stream->compr_ops->get_caps(caps);
  567. }
  568. static int sst_platform_compr_get_codec_caps(struct snd_compr_stream *cstream,
  569. struct snd_compr_codec_caps *codec)
  570. {
  571. struct sst_runtime_stream *stream =
  572. cstream->runtime->private_data;
  573. return stream->compr_ops->get_codec_caps(codec);
  574. }
  575. static struct snd_compr_ops sst_platform_compr_ops = {
  576. .open = sst_platform_compr_open,
  577. .free = sst_platform_compr_free,
  578. .set_params = sst_platform_compr_set_params,
  579. .trigger = sst_platform_compr_trigger,
  580. .pointer = sst_platform_compr_pointer,
  581. .ack = sst_platform_compr_ack,
  582. .get_caps = sst_platform_compr_get_caps,
  583. .get_codec_caps = sst_platform_compr_get_codec_caps,
  584. };
  585. static struct snd_soc_platform_driver sst_soc_platform_drv = {
  586. .ops = &sst_platform_ops,
  587. .compr_ops = &sst_platform_compr_ops,
  588. .pcm_new = sst_pcm_new,
  589. .pcm_free = sst_pcm_free,
  590. };
  591. static int sst_platform_probe(struct platform_device *pdev)
  592. {
  593. int ret;
  594. pr_debug("sst_platform_probe called\n");
  595. sst = NULL;
  596. ret = snd_soc_register_platform(&pdev->dev, &sst_soc_platform_drv);
  597. if (ret) {
  598. pr_err("registering soc platform failed\n");
  599. return ret;
  600. }
  601. ret = snd_soc_register_dais(&pdev->dev,
  602. sst_platform_dai, ARRAY_SIZE(sst_platform_dai));
  603. if (ret) {
  604. pr_err("registering cpu dais failed\n");
  605. snd_soc_unregister_platform(&pdev->dev);
  606. }
  607. return ret;
  608. }
  609. static int sst_platform_remove(struct platform_device *pdev)
  610. {
  611. snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(sst_platform_dai));
  612. snd_soc_unregister_platform(&pdev->dev);
  613. pr_debug("sst_platform_remove success\n");
  614. return 0;
  615. }
  616. static struct platform_driver sst_platform_driver = {
  617. .driver = {
  618. .name = "sst-platform",
  619. .owner = THIS_MODULE,
  620. },
  621. .probe = sst_platform_probe,
  622. .remove = sst_platform_remove,
  623. };
  624. module_platform_driver(sst_platform_driver);
  625. MODULE_DESCRIPTION("ASoC Intel(R) MID Platform driver");
  626. MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
  627. MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>");
  628. MODULE_LICENSE("GPL v2");
  629. MODULE_ALIAS("platform:sst-platform");