26 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 #include <linux/slab.h>
30 #include <linux/module.h>
44 if (!try_module_get(dev->
dev->driver->owner))
48 pr_err(
"we already have a device %s\n", sst->
name);
49 module_put(dev->
dev->driver->owner);
73 module_put(sst->
dev->driver->owner);
90 .
formats = (SNDRV_PCM_FMTBIT_S16 | SNDRV_PCM_FMTBIT_U16 |
91 SNDRV_PCM_FMTBIT_S24 | SNDRV_PCM_FMTBIT_U24 |
92 SNDRV_PCM_FMTBIT_S32 | SNDRV_PCM_FMTBIT_U32),
111 .name =
"Headset-cpu-dai",
127 .name =
"Speaker-cpu-dai",
137 .name =
"Vibra1-cpu-dai",
147 .name =
"Vibra2-cpu-dai",
157 .name =
"Compress-cpu-dai",
175 spin_unlock_irqrestore(&stream->
status_lock, flags);
185 spin_unlock_irqrestore(&stream->
status_lock, flags);
208 substream->
runtime->private_data;
214 sst_fill_pcm_params(substream, ¶m);
221 pr_debug(
"Playbck stream,Device %d\n",
222 substream->
pcm->device);
226 pr_debug(
"Capture stream,Device %d\n",
227 substream->
pcm->device);
229 ret_val = stream->
ops->open(&str_params);
230 pr_debug(
"SST_SND_PLAY/CAPTURE ret_val = %x\n", ret_val);
239 static void sst_period_elapsed(
void *mad_substream)
245 if (!substream || !substream->
runtime)
247 stream = substream->
runtime->private_data;
250 status = sst_get_stream_status(stream);
259 substream->
runtime->private_data;
262 pr_debug(
"setting buffer ptr param\n");
264 stream->
stream_info.period_elapsed = sst_period_elapsed;
268 ret_val = stream->
ops->device_control(
271 pr_err(
"control_set ret error %d\n", ret_val);
283 pr_debug(
"sst_platform_open called\n");
291 stream = kzalloc(
sizeof(*stream),
GFP_KERNEL);
299 pr_err(
"no device available to run\n");
304 if (!try_module_get(sst->
dev->driver->owner)) {
324 int ret_val = 0, str_id;
326 pr_debug(
"sst_platform_close called\n");
327 stream = substream->
runtime->private_data;
330 ret_val = stream->
ops->close(str_id);
331 module_put(sst->
dev->driver->owner);
339 int ret_val = 0, str_id;
341 pr_debug(
"sst_platform_pcm_prepare called\n");
342 stream = substream->
runtime->private_data;
345 ret_val = stream->
ops->device_control(
350 ret_val = sst_platform_alloc_stream(substream);
356 ret_val = sst_platform_init_stream(substream);
366 int ret_val = 0, str_id;
370 pr_debug(
"sst_platform_pcm_trigger called\n");
371 stream = substream->
runtime->private_data;
391 pr_debug(
"sst: in pause release\n");
398 ret_val = stream->
ops->device_control(str_cmd, &str_id);
400 sst_set_stream_status(stream, status);
413 stream = substream->
runtime->private_data;
414 status = sst_get_stream_status(stream);
418 ret_val = stream->
ops->device_control(
421 pr_err(
"sst: error code = %d\n", ret_val);
442 .open = sst_platform_open,
443 .close = sst_platform_close,
445 .prepare = sst_platform_pcm_prepare,
446 .trigger = sst_platform_pcm_trigger,
447 .pointer = sst_platform_pcm_pointer,
448 .hw_params = sst_platform_pcm_hw_params,
449 .hw_free = sst_platform_pcm_hw_free,
452 static void sst_pcm_free(
struct snd_pcm *pcm)
471 pr_err(
"dma buffer allocationf fail\n");
479 static void sst_compr_fragment_elapsed(
void *
arg)
483 pr_debug(
"fragment elapsed by driver\n");
485 snd_compr_fragment_elapsed(cstream);
495 stream = kzalloc(
sizeof(*stream),
GFP_KERNEL);
502 if (!sst || !try_module_get(sst->
dev->driver->owner)) {
503 pr_err(
"no device available to run\n");
521 int ret_val = 0, str_id;
523 stream = cstream->
runtime->private_data;
527 ret_val = stream->
compr_ops->close(str_id);
528 module_put(sst->
dev->driver->owner);
530 pr_debug(
"%s: %d\n", __func__, ret_val);
542 stream = cstream->
runtime->private_data;
544 memset(&str_params, 0,
sizeof(str_params));
550 switch (params->
codec.id) {
554 str_params.
sparams.uc.mp3_params.num_chan = params->
codec.ch_in;
555 str_params.
sparams.uc.mp3_params.pcm_wd_sz = 16;
562 str_params.
sparams.uc.aac_params.num_chan = params->
codec.ch_in;
563 str_params.
sparams.uc.aac_params.pcm_wd_sz = 16;
565 str_params.
sparams.uc.aac_params.bs_format =
568 str_params.
sparams.uc.aac_params.bs_format =
571 pr_err(
"Undefined format%d\n", params->
codec.format);
574 str_params.
sparams.uc.aac_params.externalsr =
575 params->
codec.sample_rate;
580 pr_err(
"codec not supported, id =%d\n", params->
codec.id);
584 str_params.aparams.ring_buf_info[0].addr =
586 str_params.aparams.ring_buf_info[0].size =
588 str_params.aparams.sg_count = 1;
589 str_params.aparams.frag_size = cstream->
runtime->fragment_size;
592 cb.compr_cb = sst_compr_fragment_elapsed;
594 retval = stream->compr_ops->open(&str_params, &
cb);
596 pr_err(
"stream allocation failed %d\n", retval);
604 static int sst_platform_compr_trigger(
struct snd_compr_stream *cstream,
int cmd)
607 cstream->
runtime->private_data;
609 return stream->
compr_ops->control(cmd, stream->
id);
617 stream = cstream->
runtime->private_data;
630 stream = cstream->
runtime->private_data;
631 stream->
compr_ops->ack(stream->
id, (
unsigned long)bytes);
641 cstream->
runtime->private_data;
643 return stream->
compr_ops->get_caps(caps);
646 static int sst_platform_compr_get_codec_caps(
struct snd_compr_stream *cstream,
650 cstream->
runtime->private_data;
652 return stream->
compr_ops->get_codec_caps(codec);
657 .open = sst_platform_compr_open,
658 .free = sst_platform_compr_free,
659 .set_params = sst_platform_compr_set_params,
660 .trigger = sst_platform_compr_trigger,
661 .pointer = sst_platform_compr_pointer,
662 .ack = sst_platform_compr_ack,
663 .get_caps = sst_platform_compr_get_caps,
664 .get_codec_caps = sst_platform_compr_get_codec_caps,
668 .ops = &sst_platform_ops,
669 .compr_ops = &sst_platform_compr_ops,
670 .pcm_new = sst_pcm_new,
671 .pcm_free = sst_pcm_free,
678 pr_debug(
"sst_platform_probe called\n");
682 pr_err(
"registering soc platform failed\n");
687 sst_platform_dai,
ARRAY_SIZE(sst_platform_dai));
689 pr_err(
"registering cpu dais failed\n");
700 pr_debug(
"sst_platform_remove success\n");
706 .name =
"sst-platform",
709 .probe = sst_platform_probe,
710 .remove = sst_platform_remove,