ASoC: q6dsp: q6apm-dai: Add trigger/pointer compress DAI callbacks
authorSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Mon, 19 Jun 2023 10:16:51 +0000 (11:16 +0100)
committerMark Brown <broonie@kernel.org>
Mon, 19 Jun 2023 11:59:05 +0000 (12:59 +0100)
Add q6apm trigger and pointer compress DAI callbacks to support
compress offload playback.

Co-developed-by: Mohammad Rafi Shaik <quic_mohs@quicinc.com>
Signed-off-by: Mohammad Rafi Shaik <quic_mohs@quicinc.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230619101653.9750-10-srinivas.kandagatla@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/qcom/qdsp6/q6apm-dai.c
sound/soc/qcom/qdsp6/q6apm.h

index d43705b..9543b79 100644 (file)
@@ -568,11 +568,78 @@ static int q6apm_dai_compr_get_codec_caps(struct snd_soc_component *component,
 
        return 0;
 }
+
+static int q6apm_dai_compr_pointer(struct snd_soc_component *component,
+                                  struct snd_compr_stream *stream,
+                                  struct snd_compr_tstamp *tstamp)
+{
+       struct snd_compr_runtime *runtime = stream->runtime;
+       struct q6apm_dai_rtd *prtd = runtime->private_data;
+       unsigned long flags;
+
+       spin_lock_irqsave(&prtd->lock, flags);
+       tstamp->copied_total = prtd->copied_total;
+       tstamp->byte_offset = prtd->copied_total % prtd->pcm_size;
+       spin_unlock_irqrestore(&prtd->lock, flags);
+
+       return 0;
+}
+
+static int q6apm_dai_compr_trigger(struct snd_soc_component *component,
+                           struct snd_compr_stream *stream, int cmd)
+{
+       struct snd_compr_runtime *runtime = stream->runtime;
+       struct q6apm_dai_rtd *prtd = runtime->private_data;
+       int ret = 0;
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_RESUME:
+       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+               ret = q6apm_write_async(prtd->graph, prtd->pcm_count, 0, 0, NO_TIMESTAMP);
+               break;
+       case SNDRV_PCM_TRIGGER_STOP:
+               break;
+       case SNDRV_PCM_TRIGGER_SUSPEND:
+       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+               break;
+       case SND_COMPR_TRIGGER_NEXT_TRACK:
+               prtd->next_track = true;
+               break;
+       case SND_COMPR_TRIGGER_DRAIN:
+       case SND_COMPR_TRIGGER_PARTIAL_DRAIN:
+               prtd->notify_on_drain = true;
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
+
+       return ret;
+}
+
+static int q6apm_dai_compr_ack(struct snd_soc_component *component, struct snd_compr_stream *stream,
+                       size_t count)
+{
+       struct snd_compr_runtime *runtime = stream->runtime;
+       struct q6apm_dai_rtd *prtd = runtime->private_data;
+       unsigned long flags;
+
+       spin_lock_irqsave(&prtd->lock, flags);
+       prtd->bytes_received += count;
+       spin_unlock_irqrestore(&prtd->lock, flags);
+
+       return count;
+}
+
 static const struct snd_compress_ops q6apm_dai_compress_ops = {
        .open           = q6apm_dai_compr_open,
        .free           = q6apm_dai_compr_free,
        .get_caps       = q6apm_dai_compr_get_caps,
        .get_codec_caps = q6apm_dai_compr_get_codec_caps,
+       .pointer        = q6apm_dai_compr_pointer,
+       .trigger        = q6apm_dai_compr_trigger,
+       .ack            = q6apm_dai_compr_ack,
 };
 
 static const struct snd_soc_component_driver q6apm_fe_dai_component = {
index d187d88..8ee4073 100644 (file)
@@ -46,6 +46,7 @@
 
 #define APM_MAX_SESSIONS                       8
 #define APM_LAST_BUFFER_FLAG                   BIT(30)
+#define NO_TIMESTAMP                           0xFF00
 
 struct q6apm {
        struct device *dev;