aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/mid-x86/sst_platform.c
diff options
context:
space:
mode:
authorVinod Koul <vinod.koul@linux.intel.com>2012-08-16 07:40:42 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-08-20 15:50:39 -0400
commitc514a9119a982a6c7a9fd29ee62c0ba8a8e4c7d1 (patch)
treeb5a94c730f16b0809b8425be19b67fd276da6593 /sound/soc/mid-x86/sst_platform.c
parent1245b7005de02d5bfa0c321df925f5b6c83c99e1 (diff)
ASoC: mid-x86 - add support for compressed streams
Signed-off-by: Namarta Kohli <namartax.kohli@intel.com> Signed-off-by: Ramesh Babu K V <ramesh.babu@intel.com> Signed-off-by: Vinod Koul <vinod.koul@linux.intel.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/mid-x86/sst_platform.c')
-rw-r--r--sound/soc/mid-x86/sst_platform.c204
1 files changed, 203 insertions, 1 deletions
diff --git a/sound/soc/mid-x86/sst_platform.c b/sound/soc/mid-x86/sst_platform.c
index d34563b12c3b..a263cbed8624 100644
--- a/sound/soc/mid-x86/sst_platform.c
+++ b/sound/soc/mid-x86/sst_platform.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * sst_platform.c - Intel MID Platform driver 2 * sst_platform.c - Intel MID Platform driver
3 * 3 *
4 * Copyright (C) 2010 Intel Corp 4 * Copyright (C) 2010-2012 Intel Corp
5 * Author: Vinod Koul <vinod.koul@intel.com> 5 * Author: Vinod Koul <vinod.koul@intel.com>
6 * Author: Harsha Priya <priya.harsha@intel.com> 6 * Author: Harsha Priya <priya.harsha@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -32,6 +32,7 @@
32#include <sound/pcm.h> 32#include <sound/pcm.h>
33#include <sound/pcm_params.h> 33#include <sound/pcm_params.h>
34#include <sound/soc.h> 34#include <sound/soc.h>
35#include <sound/compress_driver.h>
35#include "sst_platform.h" 36#include "sst_platform.h"
36 37
37static struct sst_device *sst; 38static struct sst_device *sst;
@@ -152,6 +153,16 @@ static struct snd_soc_dai_driver sst_platform_dai[] = {
152 .formats = SNDRV_PCM_FMTBIT_S24_LE, 153 .formats = SNDRV_PCM_FMTBIT_S24_LE,
153 }, 154 },
154}, 155},
156{
157 .name = "Compress-cpu-dai",
158 .compress_dai = 1,
159 .playback = {
160 .channels_min = SST_STEREO,
161 .channels_max = SST_STEREO,
162 .rates = SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000,
163 .formats = SNDRV_PCM_FMTBIT_S16_LE,
164 },
165},
155}; 166};
156 167
157/* helper functions */ 168/* helper functions */
@@ -463,8 +474,199 @@ static int sst_pcm_new(struct snd_soc_pcm_runtime *rtd)
463 } 474 }
464 return retval; 475 return retval;
465} 476}
477
478/* compress stream operations */
479static void sst_compr_fragment_elapsed(void *arg)
480{
481 struct snd_compr_stream *cstream = (struct snd_compr_stream *)arg;
482
483 pr_debug("fragment elapsed by driver\n");
484 if (cstream)
485 snd_compr_fragment_elapsed(cstream);
486}
487
488static int sst_platform_compr_open(struct snd_compr_stream *cstream)
489{
490
491 int ret_val = 0;
492 struct snd_compr_runtime *runtime = cstream->runtime;
493 struct sst_runtime_stream *stream;
494
495 stream = kzalloc(sizeof(*stream), GFP_KERNEL);
496 if (!stream)
497 return -ENOMEM;
498
499 spin_lock_init(&stream->status_lock);
500
501 /* get the sst ops */
502 if (!sst || !try_module_get(sst->dev->driver->owner)) {
503 pr_err("no device available to run\n");
504 ret_val = -ENODEV;
505 goto out_ops;
506 }
507 stream->compr_ops = sst->compr_ops;
508
509 stream->id = 0;
510 sst_set_stream_status(stream, SST_PLATFORM_INIT);
511 runtime->private_data = stream;
512 return 0;
513out_ops:
514 kfree(stream);
515 return ret_val;
516}
517
518static int sst_platform_compr_free(struct snd_compr_stream *cstream)
519{
520 struct sst_runtime_stream *stream;
521 int ret_val = 0, str_id;
522
523 stream = cstream->runtime->private_data;
524 /*need to check*/
525 str_id = stream->id;
526 if (str_id)
527 ret_val = stream->compr_ops->close(str_id);
528 module_put(sst->dev->driver->owner);
529 kfree(stream);
530 pr_debug("%s: %d\n", __func__, ret_val);
531 return 0;
532}
533
534static int sst_platform_compr_set_params(struct snd_compr_stream *cstream,
535 struct snd_compr_params *params)
536{
537 struct sst_runtime_stream *stream;
538 int retval;
539 struct snd_sst_params str_params;
540 struct sst_compress_cb cb;
541
542 stream = cstream->runtime->private_data;
543 /* construct fw structure for this*/
544 memset(&str_params, 0, sizeof(str_params));
545
546 str_params.ops = STREAM_OPS_PLAYBACK;
547 str_params.stream_type = SST_STREAM_TYPE_MUSIC;
548 str_params.device_type = SND_SST_DEVICE_COMPRESS;
549
550 switch (params->codec.id) {
551 case SND_AUDIOCODEC_MP3: {
552 str_params.codec = SST_CODEC_TYPE_MP3;
553 str_params.sparams.uc.mp3_params.codec = SST_CODEC_TYPE_MP3;
554 str_params.sparams.uc.mp3_params.num_chan = params->codec.ch_in;
555 str_params.sparams.uc.mp3_params.pcm_wd_sz = 16;
556 break;
557 }
558
559 case SND_AUDIOCODEC_AAC: {
560 str_params.codec = SST_CODEC_TYPE_AAC;
561 str_params.sparams.uc.aac_params.codec = SST_CODEC_TYPE_AAC;
562 str_params.sparams.uc.aac_params.num_chan = params->codec.ch_in;
563 str_params.sparams.uc.aac_params.pcm_wd_sz = 16;
564 if (params->codec.format == SND_AUDIOSTREAMFORMAT_MP4ADTS)
565 str_params.sparams.uc.aac_params.bs_format =
566 AAC_BIT_STREAM_ADTS;
567 else if (params->codec.format == SND_AUDIOSTREAMFORMAT_RAW)
568 str_params.sparams.uc.aac_params.bs_format =
569 AAC_BIT_STREAM_RAW;
570 else {
571 pr_err("Undefined format%d\n", params->codec.format);
572 return -EINVAL;
573 }
574 str_params.sparams.uc.aac_params.externalsr =
575 params->codec.sample_rate;
576 break;
577 }
578
579 default:
580 pr_err("codec not supported, id =%d\n", params->codec.id);
581 return -EINVAL;
582 }
583
584 str_params.aparams.ring_buf_info[0].addr =
585 virt_to_phys(cstream->runtime->buffer);
586 str_params.aparams.ring_buf_info[0].size =
587 cstream->runtime->buffer_size;
588 str_params.aparams.sg_count = 1;
589 str_params.aparams.frag_size = cstream->runtime->fragment_size;
590
591 cb.param = cstream;
592 cb.compr_cb = sst_compr_fragment_elapsed;
593
594 retval = stream->compr_ops->open(&str_params, &cb);
595 if (retval < 0) {
596 pr_err("stream allocation failed %d\n", retval);
597 return retval;
598 }
599
600 stream->id = retval;
601 return 0;
602}
603
604static int sst_platform_compr_trigger(struct snd_compr_stream *cstream, int cmd)
605{
606 struct sst_runtime_stream *stream =
607 cstream->runtime->private_data;
608
609 return stream->compr_ops->control(cmd, stream->id);
610}
611
612static int sst_platform_compr_pointer(struct snd_compr_stream *cstream,
613 struct snd_compr_tstamp *tstamp)
614{
615 struct sst_runtime_stream *stream;
616
617 stream = cstream->runtime->private_data;
618 stream->compr_ops->tstamp(stream->id, tstamp);
619 tstamp->byte_offset = tstamp->copied_total %
620 (u32)cstream->runtime->buffer_size;
621 pr_debug("calc bytes offset/copied bytes as %d\n", tstamp->byte_offset);
622 return 0;
623}
624
625static int sst_platform_compr_ack(struct snd_compr_stream *cstream,
626 size_t bytes)
627{
628 struct sst_runtime_stream *stream;
629
630 stream = cstream->runtime->private_data;
631 stream->compr_ops->ack(stream->id, (unsigned long)bytes);
632 stream->bytes_written += bytes;
633
634 return 0;
635}
636
637static int sst_platform_compr_get_caps(struct snd_compr_stream *cstream,
638 struct snd_compr_caps *caps)
639{
640 struct sst_runtime_stream *stream =
641 cstream->runtime->private_data;
642
643 return stream->compr_ops->get_caps(caps);
644}
645
646static int sst_platform_compr_get_codec_caps(struct snd_compr_stream *cstream,
647 struct snd_compr_codec_caps *codec)
648{
649 struct sst_runtime_stream *stream =
650 cstream->runtime->private_data;
651
652 return stream->compr_ops->get_codec_caps(codec);
653}
654
655static struct snd_compr_ops sst_platform_compr_ops = {
656
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,
665};
666
466static struct snd_soc_platform_driver sst_soc_platform_drv = { 667static struct snd_soc_platform_driver sst_soc_platform_drv = {
467 .ops = &sst_platform_ops, 668 .ops = &sst_platform_ops,
669 .compr_ops = &sst_platform_compr_ops,
468 .pcm_new = sst_pcm_new, 670 .pcm_new = sst_pcm_new,
469 .pcm_free = sst_pcm_free, 671 .pcm_free = sst_pcm_free,
470}; 672};