sst_platform.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. /*
  2. * sst_platform.c - Intel MID Platform driver
  3. *
  4. * Copyright (C) 2010-2013 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. static const struct snd_soc_component_driver sst_component = {
  159. .name = "sst",
  160. };
  161. /* helper functions */
  162. static inline void sst_set_stream_status(struct sst_runtime_stream *stream,
  163. int state)
  164. {
  165. unsigned long flags;
  166. spin_lock_irqsave(&stream->status_lock, flags);
  167. stream->stream_status = state;
  168. spin_unlock_irqrestore(&stream->status_lock, flags);
  169. }
  170. static inline int sst_get_stream_status(struct sst_runtime_stream *stream)
  171. {
  172. int state;
  173. unsigned long flags;
  174. spin_lock_irqsave(&stream->status_lock, flags);
  175. state = stream->stream_status;
  176. spin_unlock_irqrestore(&stream->status_lock, flags);
  177. return state;
  178. }
  179. static void sst_fill_pcm_params(struct snd_pcm_substream *substream,
  180. struct sst_pcm_params *param)
  181. {
  182. param->codec = SST_CODEC_TYPE_PCM;
  183. param->num_chan = (u8) substream->runtime->channels;
  184. param->pcm_wd_sz = substream->runtime->sample_bits;
  185. param->reserved = 0;
  186. param->sfreq = substream->runtime->rate;
  187. param->ring_buffer_size = snd_pcm_lib_buffer_bytes(substream);
  188. param->period_count = substream->runtime->period_size;
  189. param->ring_buffer_addr = virt_to_phys(substream->dma_buffer.area);
  190. pr_debug("period_cnt = %d\n", param->period_count);
  191. pr_debug("sfreq= %d, wd_sz = %d\n", param->sfreq, param->pcm_wd_sz);
  192. }
  193. static int sst_platform_alloc_stream(struct snd_pcm_substream *substream)
  194. {
  195. struct sst_runtime_stream *stream =
  196. substream->runtime->private_data;
  197. struct sst_pcm_params param = {0};
  198. struct sst_stream_params str_params = {0};
  199. int ret_val;
  200. /* set codec params and inform SST driver the same */
  201. sst_fill_pcm_params(substream, &param);
  202. substream->runtime->dma_area = substream->dma_buffer.area;
  203. str_params.sparams = param;
  204. str_params.codec = param.codec;
  205. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  206. str_params.ops = STREAM_OPS_PLAYBACK;
  207. str_params.device_type = substream->pcm->device + 1;
  208. pr_debug("Playbck stream,Device %d\n",
  209. substream->pcm->device);
  210. } else {
  211. str_params.ops = STREAM_OPS_CAPTURE;
  212. str_params.device_type = SND_SST_DEVICE_CAPTURE;
  213. pr_debug("Capture stream,Device %d\n",
  214. substream->pcm->device);
  215. }
  216. ret_val = stream->ops->open(&str_params);
  217. pr_debug("SST_SND_PLAY/CAPTURE ret_val = %x\n", ret_val);
  218. if (ret_val < 0)
  219. return ret_val;
  220. stream->stream_info.str_id = ret_val;
  221. pr_debug("str id : %d\n", stream->stream_info.str_id);
  222. return ret_val;
  223. }
  224. static void sst_period_elapsed(void *mad_substream)
  225. {
  226. struct snd_pcm_substream *substream = mad_substream;
  227. struct sst_runtime_stream *stream;
  228. int status;
  229. if (!substream || !substream->runtime)
  230. return;
  231. stream = substream->runtime->private_data;
  232. if (!stream)
  233. return;
  234. status = sst_get_stream_status(stream);
  235. if (status != SST_PLATFORM_RUNNING)
  236. return;
  237. snd_pcm_period_elapsed(substream);
  238. }
  239. static int sst_platform_init_stream(struct snd_pcm_substream *substream)
  240. {
  241. struct sst_runtime_stream *stream =
  242. substream->runtime->private_data;
  243. int ret_val;
  244. pr_debug("setting buffer ptr param\n");
  245. sst_set_stream_status(stream, SST_PLATFORM_INIT);
  246. stream->stream_info.period_elapsed = sst_period_elapsed;
  247. stream->stream_info.mad_substream = substream;
  248. stream->stream_info.buffer_ptr = 0;
  249. stream->stream_info.sfreq = substream->runtime->rate;
  250. ret_val = stream->ops->device_control(
  251. SST_SND_STREAM_INIT, &stream->stream_info);
  252. if (ret_val)
  253. pr_err("control_set ret error %d\n", ret_val);
  254. return ret_val;
  255. }
  256. /* end -- helper functions */
  257. static int sst_platform_open(struct snd_pcm_substream *substream)
  258. {
  259. struct snd_pcm_runtime *runtime = substream->runtime;
  260. struct sst_runtime_stream *stream;
  261. int ret_val;
  262. pr_debug("sst_platform_open called\n");
  263. snd_soc_set_runtime_hwparams(substream, &sst_platform_pcm_hw);
  264. ret_val = snd_pcm_hw_constraint_integer(runtime,
  265. SNDRV_PCM_HW_PARAM_PERIODS);
  266. if (ret_val < 0)
  267. return ret_val;
  268. stream = kzalloc(sizeof(*stream), GFP_KERNEL);
  269. if (!stream)
  270. return -ENOMEM;
  271. spin_lock_init(&stream->status_lock);
  272. /* get the sst ops */
  273. mutex_lock(&sst_lock);
  274. if (!sst) {
  275. pr_err("no device available to run\n");
  276. mutex_unlock(&sst_lock);
  277. kfree(stream);
  278. return -ENODEV;
  279. }
  280. if (!try_module_get(sst->dev->driver->owner)) {
  281. mutex_unlock(&sst_lock);
  282. kfree(stream);
  283. return -ENODEV;
  284. }
  285. stream->ops = sst->ops;
  286. mutex_unlock(&sst_lock);
  287. stream->stream_info.str_id = 0;
  288. sst_set_stream_status(stream, SST_PLATFORM_INIT);
  289. stream->stream_info.mad_substream = substream;
  290. /* allocate memory for SST API set */
  291. runtime->private_data = stream;
  292. return 0;
  293. }
  294. static int sst_platform_close(struct snd_pcm_substream *substream)
  295. {
  296. struct sst_runtime_stream *stream;
  297. int ret_val = 0, str_id;
  298. pr_debug("sst_platform_close called\n");
  299. stream = substream->runtime->private_data;
  300. str_id = stream->stream_info.str_id;
  301. if (str_id)
  302. ret_val = stream->ops->close(str_id);
  303. module_put(sst->dev->driver->owner);
  304. kfree(stream);
  305. return ret_val;
  306. }
  307. static int sst_platform_pcm_prepare(struct snd_pcm_substream *substream)
  308. {
  309. struct sst_runtime_stream *stream;
  310. int ret_val = 0, str_id;
  311. pr_debug("sst_platform_pcm_prepare called\n");
  312. stream = substream->runtime->private_data;
  313. str_id = stream->stream_info.str_id;
  314. if (stream->stream_info.str_id) {
  315. ret_val = stream->ops->device_control(
  316. SST_SND_DROP, &str_id);
  317. return ret_val;
  318. }
  319. ret_val = sst_platform_alloc_stream(substream);
  320. if (ret_val < 0)
  321. return ret_val;
  322. snprintf(substream->pcm->id, sizeof(substream->pcm->id),
  323. "%d", stream->stream_info.str_id);
  324. ret_val = sst_platform_init_stream(substream);
  325. if (ret_val)
  326. return ret_val;
  327. substream->runtime->hw.info = SNDRV_PCM_INFO_BLOCK_TRANSFER;
  328. return ret_val;
  329. }
  330. static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream,
  331. int cmd)
  332. {
  333. int ret_val = 0, str_id;
  334. struct sst_runtime_stream *stream;
  335. int str_cmd, status;
  336. pr_debug("sst_platform_pcm_trigger called\n");
  337. stream = substream->runtime->private_data;
  338. str_id = stream->stream_info.str_id;
  339. switch (cmd) {
  340. case SNDRV_PCM_TRIGGER_START:
  341. pr_debug("sst: Trigger Start\n");
  342. str_cmd = SST_SND_START;
  343. status = SST_PLATFORM_RUNNING;
  344. stream->stream_info.mad_substream = substream;
  345. break;
  346. case SNDRV_PCM_TRIGGER_STOP:
  347. pr_debug("sst: in stop\n");
  348. str_cmd = SST_SND_DROP;
  349. status = SST_PLATFORM_DROPPED;
  350. break;
  351. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  352. pr_debug("sst: in pause\n");
  353. str_cmd = SST_SND_PAUSE;
  354. status = SST_PLATFORM_PAUSED;
  355. break;
  356. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  357. pr_debug("sst: in pause release\n");
  358. str_cmd = SST_SND_RESUME;
  359. status = SST_PLATFORM_RUNNING;
  360. break;
  361. default:
  362. return -EINVAL;
  363. }
  364. ret_val = stream->ops->device_control(str_cmd, &str_id);
  365. if (!ret_val)
  366. sst_set_stream_status(stream, status);
  367. return ret_val;
  368. }
  369. static snd_pcm_uframes_t sst_platform_pcm_pointer
  370. (struct snd_pcm_substream *substream)
  371. {
  372. struct sst_runtime_stream *stream;
  373. int ret_val, status;
  374. struct pcm_stream_info *str_info;
  375. stream = substream->runtime->private_data;
  376. status = sst_get_stream_status(stream);
  377. if (status == SST_PLATFORM_INIT)
  378. return 0;
  379. str_info = &stream->stream_info;
  380. ret_val = stream->ops->device_control(
  381. SST_SND_BUFFER_POINTER, str_info);
  382. if (ret_val) {
  383. pr_err("sst: error code = %d\n", ret_val);
  384. return ret_val;
  385. }
  386. return stream->stream_info.buffer_ptr;
  387. }
  388. static int sst_platform_pcm_hw_params(struct snd_pcm_substream *substream,
  389. struct snd_pcm_hw_params *params)
  390. {
  391. snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  392. memset(substream->runtime->dma_area, 0, params_buffer_bytes(params));
  393. return 0;
  394. }
  395. static int sst_platform_pcm_hw_free(struct snd_pcm_substream *substream)
  396. {
  397. return snd_pcm_lib_free_pages(substream);
  398. }
  399. static struct snd_pcm_ops sst_platform_ops = {
  400. .open = sst_platform_open,
  401. .close = sst_platform_close,
  402. .ioctl = snd_pcm_lib_ioctl,
  403. .prepare = sst_platform_pcm_prepare,
  404. .trigger = sst_platform_pcm_trigger,
  405. .pointer = sst_platform_pcm_pointer,
  406. .hw_params = sst_platform_pcm_hw_params,
  407. .hw_free = sst_platform_pcm_hw_free,
  408. };
  409. static void sst_pcm_free(struct snd_pcm *pcm)
  410. {
  411. pr_debug("sst_pcm_free called\n");
  412. snd_pcm_lib_preallocate_free_for_all(pcm);
  413. }
  414. static int sst_pcm_new(struct snd_soc_pcm_runtime *rtd)
  415. {
  416. struct snd_pcm *pcm = rtd->pcm;
  417. int retval = 0;
  418. pr_debug("sst_pcm_new called\n");
  419. if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream ||
  420. pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
  421. retval = snd_pcm_lib_preallocate_pages_for_all(pcm,
  422. SNDRV_DMA_TYPE_CONTINUOUS,
  423. snd_dma_continuous_data(GFP_KERNEL),
  424. SST_MIN_BUFFER, SST_MAX_BUFFER);
  425. if (retval) {
  426. pr_err("dma buffer allocationf fail\n");
  427. return retval;
  428. }
  429. }
  430. return retval;
  431. }
  432. /* compress stream operations */
  433. static void sst_compr_fragment_elapsed(void *arg)
  434. {
  435. struct snd_compr_stream *cstream = (struct snd_compr_stream *)arg;
  436. pr_debug("fragment elapsed by driver\n");
  437. if (cstream)
  438. snd_compr_fragment_elapsed(cstream);
  439. }
  440. static int sst_platform_compr_open(struct snd_compr_stream *cstream)
  441. {
  442. int ret_val = 0;
  443. struct snd_compr_runtime *runtime = cstream->runtime;
  444. struct sst_runtime_stream *stream;
  445. stream = kzalloc(sizeof(*stream), GFP_KERNEL);
  446. if (!stream)
  447. return -ENOMEM;
  448. spin_lock_init(&stream->status_lock);
  449. /* get the sst ops */
  450. if (!sst || !try_module_get(sst->dev->driver->owner)) {
  451. pr_err("no device available to run\n");
  452. ret_val = -ENODEV;
  453. goto out_ops;
  454. }
  455. stream->compr_ops = sst->compr_ops;
  456. stream->id = 0;
  457. sst_set_stream_status(stream, SST_PLATFORM_INIT);
  458. runtime->private_data = stream;
  459. return 0;
  460. out_ops:
  461. kfree(stream);
  462. return ret_val;
  463. }
  464. static int sst_platform_compr_free(struct snd_compr_stream *cstream)
  465. {
  466. struct sst_runtime_stream *stream;
  467. int ret_val = 0, str_id;
  468. stream = cstream->runtime->private_data;
  469. /*need to check*/
  470. str_id = stream->id;
  471. if (str_id)
  472. ret_val = stream->compr_ops->close(str_id);
  473. module_put(sst->dev->driver->owner);
  474. kfree(stream);
  475. pr_debug("%s: %d\n", __func__, ret_val);
  476. return 0;
  477. }
  478. static int sst_platform_compr_set_params(struct snd_compr_stream *cstream,
  479. struct snd_compr_params *params)
  480. {
  481. struct sst_runtime_stream *stream;
  482. int retval;
  483. struct snd_sst_params str_params;
  484. struct sst_compress_cb cb;
  485. stream = cstream->runtime->private_data;
  486. /* construct fw structure for this*/
  487. memset(&str_params, 0, sizeof(str_params));
  488. str_params.ops = STREAM_OPS_PLAYBACK;
  489. str_params.stream_type = SST_STREAM_TYPE_MUSIC;
  490. str_params.device_type = SND_SST_DEVICE_COMPRESS;
  491. switch (params->codec.id) {
  492. case SND_AUDIOCODEC_MP3: {
  493. str_params.codec = SST_CODEC_TYPE_MP3;
  494. str_params.sparams.uc.mp3_params.codec = SST_CODEC_TYPE_MP3;
  495. str_params.sparams.uc.mp3_params.num_chan = params->codec.ch_in;
  496. str_params.sparams.uc.mp3_params.pcm_wd_sz = 16;
  497. break;
  498. }
  499. case SND_AUDIOCODEC_AAC: {
  500. str_params.codec = SST_CODEC_TYPE_AAC;
  501. str_params.sparams.uc.aac_params.codec = SST_CODEC_TYPE_AAC;
  502. str_params.sparams.uc.aac_params.num_chan = params->codec.ch_in;
  503. str_params.sparams.uc.aac_params.pcm_wd_sz = 16;
  504. if (params->codec.format == SND_AUDIOSTREAMFORMAT_MP4ADTS)
  505. str_params.sparams.uc.aac_params.bs_format =
  506. AAC_BIT_STREAM_ADTS;
  507. else if (params->codec.format == SND_AUDIOSTREAMFORMAT_RAW)
  508. str_params.sparams.uc.aac_params.bs_format =
  509. AAC_BIT_STREAM_RAW;
  510. else {
  511. pr_err("Undefined format%d\n", params->codec.format);
  512. return -EINVAL;
  513. }
  514. str_params.sparams.uc.aac_params.externalsr =
  515. params->codec.sample_rate;
  516. break;
  517. }
  518. default:
  519. pr_err("codec not supported, id =%d\n", params->codec.id);
  520. return -EINVAL;
  521. }
  522. str_params.aparams.ring_buf_info[0].addr =
  523. virt_to_phys(cstream->runtime->buffer);
  524. str_params.aparams.ring_buf_info[0].size =
  525. cstream->runtime->buffer_size;
  526. str_params.aparams.sg_count = 1;
  527. str_params.aparams.frag_size = cstream->runtime->fragment_size;
  528. cb.param = cstream;
  529. cb.compr_cb = sst_compr_fragment_elapsed;
  530. retval = stream->compr_ops->open(&str_params, &cb);
  531. if (retval < 0) {
  532. pr_err("stream allocation failed %d\n", retval);
  533. return retval;
  534. }
  535. stream->id = retval;
  536. return 0;
  537. }
  538. static int sst_platform_compr_trigger(struct snd_compr_stream *cstream, int cmd)
  539. {
  540. struct sst_runtime_stream *stream =
  541. cstream->runtime->private_data;
  542. return stream->compr_ops->control(cmd, stream->id);
  543. }
  544. static int sst_platform_compr_pointer(struct snd_compr_stream *cstream,
  545. struct snd_compr_tstamp *tstamp)
  546. {
  547. struct sst_runtime_stream *stream;
  548. stream = cstream->runtime->private_data;
  549. stream->compr_ops->tstamp(stream->id, tstamp);
  550. tstamp->byte_offset = tstamp->copied_total %
  551. (u32)cstream->runtime->buffer_size;
  552. pr_debug("calc bytes offset/copied bytes as %d\n", tstamp->byte_offset);
  553. return 0;
  554. }
  555. static int sst_platform_compr_ack(struct snd_compr_stream *cstream,
  556. size_t bytes)
  557. {
  558. struct sst_runtime_stream *stream;
  559. stream = cstream->runtime->private_data;
  560. stream->compr_ops->ack(stream->id, (unsigned long)bytes);
  561. stream->bytes_written += bytes;
  562. return 0;
  563. }
  564. static int sst_platform_compr_get_caps(struct snd_compr_stream *cstream,
  565. struct snd_compr_caps *caps)
  566. {
  567. struct sst_runtime_stream *stream =
  568. cstream->runtime->private_data;
  569. return stream->compr_ops->get_caps(caps);
  570. }
  571. static int sst_platform_compr_get_codec_caps(struct snd_compr_stream *cstream,
  572. struct snd_compr_codec_caps *codec)
  573. {
  574. struct sst_runtime_stream *stream =
  575. cstream->runtime->private_data;
  576. return stream->compr_ops->get_codec_caps(codec);
  577. }
  578. static int sst_platform_compr_set_metadata(struct snd_compr_stream *cstream,
  579. struct snd_compr_metadata *metadata)
  580. {
  581. struct sst_runtime_stream *stream =
  582. cstream->runtime->private_data;
  583. return stream->compr_ops->set_metadata(stream->id, metadata);
  584. }
  585. static struct snd_compr_ops sst_platform_compr_ops = {
  586. .open = sst_platform_compr_open,
  587. .free = sst_platform_compr_free,
  588. .set_params = sst_platform_compr_set_params,
  589. .set_metadata = sst_platform_compr_set_metadata,
  590. .trigger = sst_platform_compr_trigger,
  591. .pointer = sst_platform_compr_pointer,
  592. .ack = sst_platform_compr_ack,
  593. .get_caps = sst_platform_compr_get_caps,
  594. .get_codec_caps = sst_platform_compr_get_codec_caps,
  595. };
  596. static struct snd_soc_platform_driver sst_soc_platform_drv = {
  597. .ops = &sst_platform_ops,
  598. .compr_ops = &sst_platform_compr_ops,
  599. .pcm_new = sst_pcm_new,
  600. .pcm_free = sst_pcm_free,
  601. };
  602. static int sst_platform_probe(struct platform_device *pdev)
  603. {
  604. int ret;
  605. pr_debug("sst_platform_probe called\n");
  606. sst = NULL;
  607. ret = snd_soc_register_platform(&pdev->dev, &sst_soc_platform_drv);
  608. if (ret) {
  609. pr_err("registering soc platform failed\n");
  610. return ret;
  611. }
  612. ret = snd_soc_register_component(&pdev->dev, &sst_component,
  613. sst_platform_dai, ARRAY_SIZE(sst_platform_dai));
  614. if (ret) {
  615. pr_err("registering cpu dais failed\n");
  616. snd_soc_unregister_platform(&pdev->dev);
  617. }
  618. return ret;
  619. }
  620. static int sst_platform_remove(struct platform_device *pdev)
  621. {
  622. snd_soc_unregister_component(&pdev->dev);
  623. snd_soc_unregister_platform(&pdev->dev);
  624. pr_debug("sst_platform_remove success\n");
  625. return 0;
  626. }
  627. static struct platform_driver sst_platform_driver = {
  628. .driver = {
  629. .name = "sst-platform",
  630. .owner = THIS_MODULE,
  631. },
  632. .probe = sst_platform_probe,
  633. .remove = sst_platform_remove,
  634. };
  635. module_platform_driver(sst_platform_driver);
  636. MODULE_DESCRIPTION("ASoC Intel(R) MID Platform driver");
  637. MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
  638. MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>");
  639. MODULE_LICENSE("GPL v2");
  640. MODULE_ALIAS("platform:sst-platform");