sst_platform.c 19 KB

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