Commit 28f95795 authored by Mark Brown's avatar Mark Brown

Merge series "ASoC: qdsp6: add gapless compressed audio support" from Srinivas...

Merge series "ASoC: qdsp6: add gapless compressed audio support" from Srinivas Kandagatla <srinivas.kandagatla@linaro.org>:

This patchset adds gapless compressed audio support on q6asm.
Gapless on q6asm is implemented using 2 streams in a single q6asm session.

First few patches such as stream id per each command, gapless flags
and silence meta data are for preparedness for adding gapless support.
Last patch implements copy callback to allow finer control over buffer offsets,
specially in partial drain cases.

This patchset is tested on RB3 aka DB845c platform.

This patchset as it is will support gapless however QDSP can also
support switching decoders on a single stream. Patches to support such feature
are send in different patchset which involves adding generic interfaces.

Thanks,
srini

Changes since v2:(mostly suggested by Pierre)
- removed unnessary kernel style comments,
- moved TIMESTAMP flag to respective patch.
- move preparatory code from gapless support patch to new one.
- fix subject prefix of one patch.
- add comments to clarify valid stream_ids

Srinivas Kandagatla (10):
  ASoC: q6asm: rename misleading session id variable
  ASoC: q6asm: make commands specific to streams
  ASoC: q6asm: use flags directly from q6asm-dai
  ASoC: q6asm: add length to write command token
  ASoC: q6asm: add support to remove intial and trailing silence
  ASoC: q6asm: add support to gapless flag in q6asm open
  ASoC: q6asm-dai: add next track metadata support
  ASoC: q6asm-dai: prepare set params to accept profile change
  ASoC: q6asm-dai: add gapless support
  ASoC: q6asm-dai: add support to copy callback

 sound/soc/qcom/qdsp6/q6asm-dai.c | 414 +++++++++++++++++++++++--------
 sound/soc/qcom/qdsp6/q6asm.c     | 169 +++++++++----
 sound/soc/qcom/qdsp6/q6asm.h     |  49 ++--
 3 files changed, 469 insertions(+), 163 deletions(-)

--
2.21.0
parents 5ca8f9a5 a08cd56a
...@@ -50,7 +50,7 @@ enum stream_state { ...@@ -50,7 +50,7 @@ enum stream_state {
struct q6asm_dai_rtd { struct q6asm_dai_rtd {
struct snd_pcm_substream *substream; struct snd_pcm_substream *substream;
struct snd_compr_stream *cstream; struct snd_compr_stream *cstream;
struct snd_compr_params codec_param; struct snd_codec codec;
struct snd_dma_buffer dma_buffer; struct snd_dma_buffer dma_buffer;
spinlock_t lock; spinlock_t lock;
phys_addr_t phys; phys_addr_t phys;
...@@ -64,8 +64,14 @@ struct q6asm_dai_rtd { ...@@ -64,8 +64,14 @@ struct q6asm_dai_rtd {
uint16_t bits_per_sample; uint16_t bits_per_sample;
uint16_t source; /* Encoding source bit mask */ uint16_t source; /* Encoding source bit mask */
struct audio_client *audio_client; struct audio_client *audio_client;
uint32_t next_track_stream_id;
bool next_track;
uint32_t stream_id;
uint16_t session_id; uint16_t session_id;
enum stream_state state; enum stream_state state;
uint32_t initial_samples_drop;
uint32_t trailing_samples_drop;
bool notify_on_drain;
}; };
struct q6asm_dai_data { struct q6asm_dai_data {
...@@ -181,8 +187,8 @@ static void event_handler(uint32_t opcode, uint32_t token, ...@@ -181,8 +187,8 @@ static void event_handler(uint32_t opcode, uint32_t token,
switch (opcode) { switch (opcode) {
case ASM_CLIENT_EVENT_CMD_RUN_DONE: case ASM_CLIENT_EVENT_CMD_RUN_DONE:
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
q6asm_write_async(prtd->audio_client, q6asm_write_async(prtd->audio_client, prtd->stream_id,
prtd->pcm_count, 0, 0, NO_TIMESTAMP); prtd->pcm_count, 0, 0, 0);
break; break;
case ASM_CLIENT_EVENT_CMD_EOS_DONE: case ASM_CLIENT_EVENT_CMD_EOS_DONE:
prtd->state = Q6ASM_STREAM_STOPPED; prtd->state = Q6ASM_STREAM_STOPPED;
...@@ -191,8 +197,8 @@ static void event_handler(uint32_t opcode, uint32_t token, ...@@ -191,8 +197,8 @@ static void event_handler(uint32_t opcode, uint32_t token,
prtd->pcm_irq_pos += prtd->pcm_count; prtd->pcm_irq_pos += prtd->pcm_count;
snd_pcm_period_elapsed(substream); snd_pcm_period_elapsed(substream);
if (prtd->state == Q6ASM_STREAM_RUNNING) if (prtd->state == Q6ASM_STREAM_RUNNING)
q6asm_write_async(prtd->audio_client, q6asm_write_async(prtd->audio_client, prtd->stream_id,
prtd->pcm_count, 0, 0, NO_TIMESTAMP); prtd->pcm_count, 0, 0, 0);
break; break;
} }
...@@ -200,7 +206,7 @@ static void event_handler(uint32_t opcode, uint32_t token, ...@@ -200,7 +206,7 @@ static void event_handler(uint32_t opcode, uint32_t token,
prtd->pcm_irq_pos += prtd->pcm_count; prtd->pcm_irq_pos += prtd->pcm_count;
snd_pcm_period_elapsed(substream); snd_pcm_period_elapsed(substream);
if (prtd->state == Q6ASM_STREAM_RUNNING) if (prtd->state == Q6ASM_STREAM_RUNNING)
q6asm_read(prtd->audio_client); q6asm_read(prtd->audio_client, prtd->stream_id);
break; break;
default: default:
...@@ -233,7 +239,7 @@ static int q6asm_dai_prepare(struct snd_soc_component *component, ...@@ -233,7 +239,7 @@ static int q6asm_dai_prepare(struct snd_soc_component *component,
/* rate and channels are sent to audio driver */ /* rate and channels are sent to audio driver */
if (prtd->state) { if (prtd->state) {
/* clear the previous setup if any */ /* clear the previous setup if any */
q6asm_cmd(prtd->audio_client, CMD_CLOSE); q6asm_cmd(prtd->audio_client, prtd->stream_id, CMD_CLOSE);
q6asm_unmap_memory_regions(substream->stream, q6asm_unmap_memory_regions(substream->stream,
prtd->audio_client); prtd->audio_client);
q6routing_stream_close(soc_prtd->dai_link->id, q6routing_stream_close(soc_prtd->dai_link->id,
...@@ -252,11 +258,13 @@ static int q6asm_dai_prepare(struct snd_soc_component *component, ...@@ -252,11 +258,13 @@ static int q6asm_dai_prepare(struct snd_soc_component *component,
} }
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
ret = q6asm_open_write(prtd->audio_client, FORMAT_LINEAR_PCM, ret = q6asm_open_write(prtd->audio_client, prtd->stream_id,
0, prtd->bits_per_sample); FORMAT_LINEAR_PCM,
0, prtd->bits_per_sample, false);
} else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
ret = q6asm_open_read(prtd->audio_client, FORMAT_LINEAR_PCM, ret = q6asm_open_read(prtd->audio_client, prtd->stream_id,
prtd->bits_per_sample); FORMAT_LINEAR_PCM,
prtd->bits_per_sample);
} }
if (ret < 0) { if (ret < 0) {
...@@ -276,17 +284,19 @@ static int q6asm_dai_prepare(struct snd_soc_component *component, ...@@ -276,17 +284,19 @@ static int q6asm_dai_prepare(struct snd_soc_component *component,
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
ret = q6asm_media_format_block_multi_ch_pcm( ret = q6asm_media_format_block_multi_ch_pcm(
prtd->audio_client, runtime->rate, prtd->audio_client, prtd->stream_id,
runtime->channels, NULL, runtime->rate, runtime->channels, NULL,
prtd->bits_per_sample); prtd->bits_per_sample);
} else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
ret = q6asm_enc_cfg_blk_pcm_format_support(prtd->audio_client, ret = q6asm_enc_cfg_blk_pcm_format_support(prtd->audio_client,
runtime->rate, runtime->channels, prtd->stream_id,
prtd->bits_per_sample); runtime->rate,
runtime->channels,
prtd->bits_per_sample);
/* Queue the buffers */ /* Queue the buffers */
for (i = 0; i < runtime->periods; i++) for (i = 0; i < runtime->periods; i++)
q6asm_read(prtd->audio_client); q6asm_read(prtd->audio_client, prtd->stream_id);
} }
if (ret < 0) if (ret < 0)
...@@ -308,15 +318,18 @@ static int q6asm_dai_trigger(struct snd_soc_component *component, ...@@ -308,15 +318,18 @@ static int q6asm_dai_trigger(struct snd_soc_component *component,
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
ret = q6asm_run_nowait(prtd->audio_client, 0, 0, 0); ret = q6asm_run_nowait(prtd->audio_client, prtd->stream_id,
0, 0, 0);
break; break;
case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_STOP:
prtd->state = Q6ASM_STREAM_STOPPED; prtd->state = Q6ASM_STREAM_STOPPED;
ret = q6asm_cmd_nowait(prtd->audio_client, CMD_EOS); ret = q6asm_cmd_nowait(prtd->audio_client, prtd->stream_id,
CMD_EOS);
break; break;
case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
ret = q6asm_cmd_nowait(prtd->audio_client, CMD_PAUSE); ret = q6asm_cmd_nowait(prtd->audio_client, prtd->stream_id,
CMD_PAUSE);
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
...@@ -361,6 +374,9 @@ static int q6asm_dai_open(struct snd_soc_component *component, ...@@ -361,6 +374,9 @@ static int q6asm_dai_open(struct snd_soc_component *component,
return ret; return ret;
} }
/* DSP expects stream id from 1 */
prtd->stream_id = 1;
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
runtime->hw = q6asm_dai_hardware_playback; runtime->hw = q6asm_dai_hardware_playback;
else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
...@@ -427,7 +443,8 @@ static int q6asm_dai_close(struct snd_soc_component *component, ...@@ -427,7 +443,8 @@ static int q6asm_dai_close(struct snd_soc_component *component,
if (prtd->audio_client) { if (prtd->audio_client) {
if (prtd->state) if (prtd->state)
q6asm_cmd(prtd->audio_client, CMD_CLOSE); q6asm_cmd(prtd->audio_client, prtd->stream_id,
CMD_CLOSE);
q6asm_unmap_memory_regions(substream->stream, q6asm_unmap_memory_regions(substream->stream,
prtd->audio_client); prtd->audio_client);
...@@ -493,14 +510,21 @@ static void compress_event_handler(uint32_t opcode, uint32_t token, ...@@ -493,14 +510,21 @@ static void compress_event_handler(uint32_t opcode, uint32_t token,
struct q6asm_dai_rtd *prtd = priv; struct q6asm_dai_rtd *prtd = priv;
struct snd_compr_stream *substream = prtd->cstream; struct snd_compr_stream *substream = prtd->cstream;
unsigned long flags; unsigned long flags;
u32 wflags = 0;
uint64_t avail; uint64_t avail;
uint32_t bytes_written, bytes_to_write;
bool is_last_buffer = false;
switch (opcode) { switch (opcode) {
case ASM_CLIENT_EVENT_CMD_RUN_DONE: case ASM_CLIENT_EVENT_CMD_RUN_DONE:
spin_lock_irqsave(&prtd->lock, flags); spin_lock_irqsave(&prtd->lock, flags);
if (!prtd->bytes_sent) { if (!prtd->bytes_sent) {
q6asm_write_async(prtd->audio_client, prtd->pcm_count, q6asm_stream_remove_initial_silence(prtd->audio_client,
0, 0, NO_TIMESTAMP); prtd->stream_id,
prtd->initial_samples_drop);
q6asm_write_async(prtd->audio_client, prtd->stream_id,
prtd->pcm_count, 0, 0, 0);
prtd->bytes_sent += prtd->pcm_count; prtd->bytes_sent += prtd->pcm_count;
} }
...@@ -508,13 +532,37 @@ static void compress_event_handler(uint32_t opcode, uint32_t token, ...@@ -508,13 +532,37 @@ static void compress_event_handler(uint32_t opcode, uint32_t token,
break; break;
case ASM_CLIENT_EVENT_CMD_EOS_DONE: case ASM_CLIENT_EVENT_CMD_EOS_DONE:
prtd->state = Q6ASM_STREAM_STOPPED; spin_lock_irqsave(&prtd->lock, flags);
if (prtd->notify_on_drain) {
if (substream->partial_drain) {
/*
* Close old stream and make it stale, switch
* the active stream now!
*/
q6asm_cmd_nowait(prtd->audio_client,
prtd->stream_id,
CMD_CLOSE);
/*
* vaild stream ids start from 1, So we are
* toggling this between 1 and 2.
*/
prtd->stream_id = (prtd->stream_id == 1 ? 2 : 1);
}
snd_compr_drain_notify(prtd->cstream);
prtd->notify_on_drain = false;
} else {
prtd->state = Q6ASM_STREAM_STOPPED;
}
spin_unlock_irqrestore(&prtd->lock, flags);
break; break;
case ASM_CLIENT_EVENT_DATA_WRITE_DONE: case ASM_CLIENT_EVENT_DATA_WRITE_DONE:
spin_lock_irqsave(&prtd->lock, flags); spin_lock_irqsave(&prtd->lock, flags);
prtd->copied_total += prtd->pcm_count; bytes_written = token >> ASM_WRITE_TOKEN_LEN_SHIFT;
prtd->copied_total += bytes_written;
snd_compr_fragment_elapsed(substream); snd_compr_fragment_elapsed(substream);
if (prtd->state != Q6ASM_STREAM_RUNNING) { if (prtd->state != Q6ASM_STREAM_RUNNING) {
...@@ -523,13 +571,32 @@ static void compress_event_handler(uint32_t opcode, uint32_t token, ...@@ -523,13 +571,32 @@ static void compress_event_handler(uint32_t opcode, uint32_t token,
} }
avail = prtd->bytes_received - prtd->bytes_sent; avail = prtd->bytes_received - prtd->bytes_sent;
if (avail > prtd->pcm_count) {
bytes_to_write = prtd->pcm_count;
} else {
if (substream->partial_drain || prtd->notify_on_drain)
is_last_buffer = true;
bytes_to_write = avail;
}
if (avail >= prtd->pcm_count) { if (bytes_to_write) {
q6asm_write_async(prtd->audio_client, if (substream->partial_drain && is_last_buffer) {
prtd->pcm_count, 0, 0, NO_TIMESTAMP); wflags |= ASM_LAST_BUFFER_FLAG;
prtd->bytes_sent += prtd->pcm_count; q6asm_stream_remove_trailing_silence(prtd->audio_client,
prtd->stream_id,
prtd->trailing_samples_drop);
}
q6asm_write_async(prtd->audio_client, prtd->stream_id,
bytes_to_write, 0, 0, wflags);
prtd->bytes_sent += bytes_to_write;
} }
if (prtd->notify_on_drain && is_last_buffer)
q6asm_cmd_nowait(prtd->audio_client,
prtd->stream_id, CMD_EOS);
spin_unlock_irqrestore(&prtd->lock, flags); spin_unlock_irqrestore(&prtd->lock, flags);
break; break;
...@@ -560,6 +627,9 @@ static int q6asm_dai_compr_open(struct snd_soc_component *component, ...@@ -560,6 +627,9 @@ static int q6asm_dai_compr_open(struct snd_soc_component *component,
if (!prtd) if (!prtd)
return -ENOMEM; return -ENOMEM;
/* DSP expects stream id from 1 */
prtd->stream_id = 1;
prtd->cstream = stream; prtd->cstream = stream;
prtd->audio_client = q6asm_audio_client_alloc(dev, prtd->audio_client = q6asm_audio_client_alloc(dev,
(q6asm_cb)compress_event_handler, (q6asm_cb)compress_event_handler,
...@@ -606,8 +676,15 @@ static int q6asm_dai_compr_free(struct snd_soc_component *component, ...@@ -606,8 +676,15 @@ static int q6asm_dai_compr_free(struct snd_soc_component *component,
struct snd_soc_pcm_runtime *rtd = stream->private_data; struct snd_soc_pcm_runtime *rtd = stream->private_data;
if (prtd->audio_client) { if (prtd->audio_client) {
if (prtd->state) if (prtd->state) {
q6asm_cmd(prtd->audio_client, CMD_CLOSE); q6asm_cmd(prtd->audio_client, prtd->stream_id,
CMD_CLOSE);
if (prtd->next_track_stream_id) {
q6asm_cmd(prtd->audio_client,
prtd->next_track_stream_id,
CMD_CLOSE);
}
}
snd_dma_free_pages(&prtd->dma_buffer); snd_dma_free_pages(&prtd->dma_buffer);
q6asm_unmap_memory_regions(stream->direction, q6asm_unmap_memory_regions(stream->direction,
...@@ -621,15 +698,13 @@ static int q6asm_dai_compr_free(struct snd_soc_component *component, ...@@ -621,15 +698,13 @@ static int q6asm_dai_compr_free(struct snd_soc_component *component,
return 0; return 0;
} }
static int q6asm_dai_compr_set_params(struct snd_soc_component *component, static int __q6asm_dai_compr_set_codec_params(struct snd_soc_component *component,
struct snd_compr_stream *stream, struct snd_compr_stream *stream,
struct snd_compr_params *params) struct snd_codec *codec,
int stream_id)
{ {
struct snd_compr_runtime *runtime = stream->runtime; struct snd_compr_runtime *runtime = stream->runtime;
struct q6asm_dai_rtd *prtd = runtime->private_data; struct q6asm_dai_rtd *prtd = runtime->private_data;
struct snd_soc_pcm_runtime *rtd = stream->private_data;
int dir = stream->direction;
struct q6asm_dai_data *pdata;
struct q6asm_flac_cfg flac_cfg; struct q6asm_flac_cfg flac_cfg;
struct q6asm_wma_cfg wma_cfg; struct q6asm_wma_cfg wma_cfg;
struct q6asm_alac_cfg alac_cfg; struct q6asm_alac_cfg alac_cfg;
...@@ -643,52 +718,18 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component, ...@@ -643,52 +718,18 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component,
struct snd_dec_alac *alac; struct snd_dec_alac *alac;
struct snd_dec_ape *ape; struct snd_dec_ape *ape;
codec_options = &(prtd->codec_param.codec.options); codec_options = &(prtd->codec.options);
memcpy(&prtd->codec_param, params, sizeof(*params));
pdata = snd_soc_component_get_drvdata(component);
if (!pdata)
return -EINVAL;
if (!prtd || !prtd->audio_client) {
dev_err(dev, "private data null or audio client freed\n");
return -EINVAL;
}
prtd->periods = runtime->fragments;
prtd->pcm_count = runtime->fragment_size;
prtd->pcm_size = runtime->fragments * runtime->fragment_size;
prtd->bits_per_sample = 16;
if (dir == SND_COMPRESS_PLAYBACK) {
ret = q6asm_open_write(prtd->audio_client, params->codec.id,
params->codec.profile, prtd->bits_per_sample);
if (ret < 0) {
dev_err(dev, "q6asm_open_write failed\n");
q6asm_audio_client_free(prtd->audio_client);
prtd->audio_client = NULL;
return ret;
}
}
prtd->session_id = q6asm_get_session_id(prtd->audio_client); memcpy(&prtd->codec, codec, sizeof(*codec));
ret = q6routing_stream_open(rtd->dai_link->id, LEGACY_PCM_MODE,
prtd->session_id, dir);
if (ret) {
dev_err(dev, "Stream reg failed ret:%d\n", ret);
return ret;
}
switch (params->codec.id) { switch (codec->id) {
case SND_AUDIOCODEC_FLAC: case SND_AUDIOCODEC_FLAC:
memset(&flac_cfg, 0x0, sizeof(struct q6asm_flac_cfg)); memset(&flac_cfg, 0x0, sizeof(struct q6asm_flac_cfg));
flac = &codec_options->flac_d; flac = &codec_options->flac_d;
flac_cfg.ch_cfg = params->codec.ch_in; flac_cfg.ch_cfg = codec->ch_in;
flac_cfg.sample_rate = params->codec.sample_rate; flac_cfg.sample_rate = codec->sample_rate;
flac_cfg.stream_info_present = 1; flac_cfg.stream_info_present = 1;
flac_cfg.sample_size = flac->sample_size; flac_cfg.sample_size = flac->sample_size;
flac_cfg.min_blk_size = flac->min_blk_size; flac_cfg.min_blk_size = flac->min_blk_size;
...@@ -697,6 +738,7 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component, ...@@ -697,6 +738,7 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component,
flac_cfg.min_frame_size = flac->min_frame_size; flac_cfg.min_frame_size = flac->min_frame_size;
ret = q6asm_stream_media_format_block_flac(prtd->audio_client, ret = q6asm_stream_media_format_block_flac(prtd->audio_client,
stream_id,
&flac_cfg); &flac_cfg);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "FLAC CMD Format block failed:%d\n", ret); dev_err(dev, "FLAC CMD Format block failed:%d\n", ret);
...@@ -709,10 +751,10 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component, ...@@ -709,10 +751,10 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component,
memset(&wma_cfg, 0x0, sizeof(struct q6asm_wma_cfg)); memset(&wma_cfg, 0x0, sizeof(struct q6asm_wma_cfg));
wma_cfg.sample_rate = params->codec.sample_rate; wma_cfg.sample_rate = codec->sample_rate;
wma_cfg.num_channels = params->codec.ch_in; wma_cfg.num_channels = codec->ch_in;
wma_cfg.bytes_per_sec = params->codec.bit_rate / 8; wma_cfg.bytes_per_sec = codec->bit_rate / 8;
wma_cfg.block_align = params->codec.align; wma_cfg.block_align = codec->align;
wma_cfg.bits_per_sample = prtd->bits_per_sample; wma_cfg.bits_per_sample = prtd->bits_per_sample;
wma_cfg.enc_options = wma->encoder_option; wma_cfg.enc_options = wma->encoder_option;
wma_cfg.adv_enc_options = wma->adv_encoder_option; wma_cfg.adv_enc_options = wma->adv_encoder_option;
...@@ -726,7 +768,7 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component, ...@@ -726,7 +768,7 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component,
return -EINVAL; return -EINVAL;
/* check the codec profile */ /* check the codec profile */
switch (params->codec.profile) { switch (codec->profile) {
case SND_AUDIOPROFILE_WMA9: case SND_AUDIOPROFILE_WMA9:
wma_cfg.fmtag = 0x161; wma_cfg.fmtag = 0x161;
wma_v9 = 1; wma_v9 = 1;
...@@ -750,16 +792,18 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component, ...@@ -750,16 +792,18 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component,
default: default:
dev_err(dev, "Unknown WMA profile:%x\n", dev_err(dev, "Unknown WMA profile:%x\n",
params->codec.profile); codec->profile);
return -EIO; return -EIO;
} }
if (wma_v9) if (wma_v9)
ret = q6asm_stream_media_format_block_wma_v9( ret = q6asm_stream_media_format_block_wma_v9(
prtd->audio_client, &wma_cfg); prtd->audio_client, stream_id,
&wma_cfg);
else else
ret = q6asm_stream_media_format_block_wma_v10( ret = q6asm_stream_media_format_block_wma_v10(
prtd->audio_client, &wma_cfg); prtd->audio_client, stream_id,
&wma_cfg);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "WMA9 CMD failed:%d\n", ret); dev_err(dev, "WMA9 CMD failed:%d\n", ret);
return -EIO; return -EIO;
...@@ -770,10 +814,10 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component, ...@@ -770,10 +814,10 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component,
memset(&alac_cfg, 0x0, sizeof(alac_cfg)); memset(&alac_cfg, 0x0, sizeof(alac_cfg));
alac = &codec_options->alac_d; alac = &codec_options->alac_d;
alac_cfg.sample_rate = params->codec.sample_rate; alac_cfg.sample_rate = codec->sample_rate;
alac_cfg.avg_bit_rate = params->codec.bit_rate; alac_cfg.avg_bit_rate = codec->bit_rate;
alac_cfg.bit_depth = prtd->bits_per_sample; alac_cfg.bit_depth = prtd->bits_per_sample;
alac_cfg.num_channels = params->codec.ch_in; alac_cfg.num_channels = codec->ch_in;
alac_cfg.frame_length = alac->frame_length; alac_cfg.frame_length = alac->frame_length;
alac_cfg.pb = alac->pb; alac_cfg.pb = alac->pb;
...@@ -783,7 +827,7 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component, ...@@ -783,7 +827,7 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component,
alac_cfg.compatible_version = alac->compatible_version; alac_cfg.compatible_version = alac->compatible_version;
alac_cfg.max_frame_bytes = alac->max_frame_bytes; alac_cfg.max_frame_bytes = alac->max_frame_bytes;
switch (params->codec.ch_in) { switch (codec->ch_in) {
case 1: case 1:
alac_cfg.channel_layout_tag = ALAC_CH_LAYOUT_MONO; alac_cfg.channel_layout_tag = ALAC_CH_LAYOUT_MONO;
break; break;
...@@ -792,6 +836,7 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component, ...@@ -792,6 +836,7 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component,
break; break;
} }
ret = q6asm_stream_media_format_block_alac(prtd->audio_client, ret = q6asm_stream_media_format_block_alac(prtd->audio_client,
stream_id,
&alac_cfg); &alac_cfg);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "ALAC CMD Format block failed:%d\n", ret); dev_err(dev, "ALAC CMD Format block failed:%d\n", ret);
...@@ -803,8 +848,8 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component, ...@@ -803,8 +848,8 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component,
memset(&ape_cfg, 0x0, sizeof(ape_cfg)); memset(&ape_cfg, 0x0, sizeof(ape_cfg));
ape = &codec_options->ape_d; ape = &codec_options->ape_d;
ape_cfg.sample_rate = params->codec.sample_rate; ape_cfg.sample_rate = codec->sample_rate;
ape_cfg.num_channels = params->codec.ch_in; ape_cfg.num_channels = codec->ch_in;
ape_cfg.bits_per_sample = prtd->bits_per_sample; ape_cfg.bits_per_sample = prtd->bits_per_sample;
ape_cfg.compatible_version = ape->compatible_version; ape_cfg.compatible_version = ape->compatible_version;
...@@ -816,6 +861,7 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component, ...@@ -816,6 +861,7 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component,
ape_cfg.seek_table_present = ape->seek_table_present; ape_cfg.seek_table_present = ape->seek_table_present;
ret = q6asm_stream_media_format_block_ape(prtd->audio_client, ret = q6asm_stream_media_format_block_ape(prtd->audio_client,
stream_id,
&ape_cfg); &ape_cfg);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "APE CMD Format block failed:%d\n", ret); dev_err(dev, "APE CMD Format block failed:%d\n", ret);
...@@ -827,6 +873,64 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component, ...@@ -827,6 +873,64 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component,
break; break;
} }
return 0;
}
static int q6asm_dai_compr_set_params(struct snd_soc_component *component,
struct snd_compr_stream *stream,
struct snd_compr_params *params)
{
struct snd_compr_runtime *runtime = stream->runtime;
struct q6asm_dai_rtd *prtd = runtime->private_data;
struct snd_soc_pcm_runtime *rtd = stream->private_data;
int dir = stream->direction;
struct q6asm_dai_data *pdata;
struct device *dev = component->dev;
int ret;
pdata = snd_soc_component_get_drvdata(component);
if (!pdata)
return -EINVAL;
if (!prtd || !prtd->audio_client) {
dev_err(dev, "private data null or audio client freed\n");
return -EINVAL;
}
prtd->periods = runtime->fragments;
prtd->pcm_count = runtime->fragment_size;
prtd->pcm_size = runtime->fragments * runtime->fragment_size;
prtd->bits_per_sample = 16;
if (dir == SND_COMPRESS_PLAYBACK) {
ret = q6asm_open_write(prtd->audio_client, prtd->stream_id, params->codec.id,
params->codec.profile, prtd->bits_per_sample,
true);
if (ret < 0) {
dev_err(dev, "q6asm_open_write failed\n");
q6asm_audio_client_free(prtd->audio_client);
prtd->audio_client = NULL;
return ret;
}
}
prtd->session_id = q6asm_get_session_id(prtd->audio_client);
ret = q6routing_stream_open(rtd->dai_link->id, LEGACY_PCM_MODE,
prtd->session_id, dir);
if (ret) {
dev_err(dev, "Stream reg failed ret:%d\n", ret);
return ret;
}
ret = __q6asm_dai_compr_set_codec_params(component, stream,
&params->codec,
prtd->stream_id);
if (ret) {
dev_err(dev, "codec param setup failed ret:%d\n", ret);
return ret;
}
ret = q6asm_map_memory_regions(dir, prtd->audio_client, prtd->phys, ret = q6asm_map_memory_regions(dir, prtd->audio_client, prtd->phys,
(prtd->pcm_size / prtd->periods), (prtd->pcm_size / prtd->periods),
prtd->periods); prtd->periods);
...@@ -841,6 +945,55 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component, ...@@ -841,6 +945,55 @@ static int q6asm_dai_compr_set_params(struct snd_soc_component *component,
return 0; return 0;
} }
static int q6asm_dai_compr_set_metadata(struct snd_soc_component *component,
struct snd_compr_stream *stream,
struct snd_compr_metadata *metadata)
{
struct snd_compr_runtime *runtime = stream->runtime;
struct q6asm_dai_rtd *prtd = runtime->private_data;
int ret = 0;
switch (metadata->key) {
case SNDRV_COMPRESS_ENCODER_PADDING:
prtd->trailing_samples_drop = metadata->value[0];
break;
case SNDRV_COMPRESS_ENCODER_DELAY:
prtd->initial_samples_drop = metadata->value[0];
if (prtd->next_track_stream_id) {
ret = q6asm_open_write(prtd->audio_client,
prtd->next_track_stream_id,
prtd->codec.id,
prtd->codec.profile,
prtd->bits_per_sample,
true);
if (ret < 0) {
dev_err(component->dev, "q6asm_open_write failed\n");
return ret;
}
ret = __q6asm_dai_compr_set_codec_params(component, stream,
&prtd->codec,
prtd->next_track_stream_id);
if (ret < 0) {
dev_err(component->dev, "q6asm_open_write failed\n");
return ret;
}
ret = q6asm_stream_remove_initial_silence(prtd->audio_client,
prtd->next_track_stream_id,
prtd->initial_samples_drop);
prtd->next_track_stream_id = 0;
}
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
static int q6asm_dai_compr_trigger(struct snd_soc_component *component, static int q6asm_dai_compr_trigger(struct snd_soc_component *component,
struct snd_compr_stream *stream, int cmd) struct snd_compr_stream *stream, int cmd)
{ {
...@@ -852,15 +1005,26 @@ static int q6asm_dai_compr_trigger(struct snd_soc_component *component, ...@@ -852,15 +1005,26 @@ static int q6asm_dai_compr_trigger(struct snd_soc_component *component,
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
ret = q6asm_run_nowait(prtd->audio_client, 0, 0, 0); ret = q6asm_run_nowait(prtd->audio_client, prtd->stream_id,
0, 0, 0);
break; break;
case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_STOP:
prtd->state = Q6ASM_STREAM_STOPPED; prtd->state = Q6ASM_STREAM_STOPPED;
ret = q6asm_cmd_nowait(prtd->audio_client, CMD_EOS); ret = q6asm_cmd_nowait(prtd->audio_client, prtd->stream_id,
CMD_EOS);
break; break;
case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
ret = q6asm_cmd_nowait(prtd->audio_client, CMD_PAUSE); ret = q6asm_cmd_nowait(prtd->audio_client, prtd->stream_id,
CMD_PAUSE);
break;
case SND_COMPR_TRIGGER_NEXT_TRACK:
prtd->next_track = true;
prtd->next_track_stream_id = (prtd->stream_id == 1 ? 2 : 1);
break;
case SND_COMPR_TRIGGER_DRAIN:
case SND_COMPR_TRIGGER_PARTIAL_DRAIN:
prtd->notify_on_drain = true;
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
...@@ -888,16 +1052,71 @@ static int q6asm_dai_compr_pointer(struct snd_soc_component *component, ...@@ -888,16 +1052,71 @@ static int q6asm_dai_compr_pointer(struct snd_soc_component *component,
return 0; return 0;
} }
static int q6asm_dai_compr_ack(struct snd_soc_component *component, static int q6asm_compr_copy(struct snd_soc_component *component,
struct snd_compr_stream *stream, struct snd_compr_stream *stream, char __user *buf,
size_t count) size_t count)
{ {
struct snd_compr_runtime *runtime = stream->runtime; struct snd_compr_runtime *runtime = stream->runtime;
struct q6asm_dai_rtd *prtd = runtime->private_data; struct q6asm_dai_rtd *prtd = runtime->private_data;
unsigned long flags; unsigned long flags;
u32 wflags = 0;
int avail, bytes_in_flight = 0;
void *dstn;
size_t copy;
u32 app_pointer;
u32 bytes_received;
bytes_received = prtd->bytes_received;
/**
* Make sure that next track data pointer is aligned at 32 bit boundary
* This is a Mandatory requirement from DSP data buffers alignment
*/
if (prtd->next_track)
bytes_received = ALIGN(prtd->bytes_received, prtd->pcm_count);
app_pointer = bytes_received/prtd->pcm_size;
app_pointer = bytes_received - (app_pointer * prtd->pcm_size);
dstn = prtd->dma_buffer.area + app_pointer;
if (count < prtd->pcm_size - app_pointer) {
if (copy_from_user(dstn, buf, count))
return -EFAULT;
} else {
copy = prtd->pcm_size - app_pointer;
if (copy_from_user(dstn, buf, copy))
return -EFAULT;
if (copy_from_user(prtd->dma_buffer.area, buf + copy,
count - copy))
return -EFAULT;
}
spin_lock_irqsave(&prtd->lock, flags); spin_lock_irqsave(&prtd->lock, flags);
prtd->bytes_received += count;
bytes_in_flight = prtd->bytes_received - prtd->copied_total;
if (prtd->next_track) {
prtd->next_track = false;
prtd->copied_total = ALIGN(prtd->copied_total, prtd->pcm_count);
prtd->bytes_sent = ALIGN(prtd->bytes_sent, prtd->pcm_count);
}
prtd->bytes_received = bytes_received + count;
/* Kick off the data to dsp if its starving!! */
if (prtd->state == Q6ASM_STREAM_RUNNING && (bytes_in_flight == 0)) {
uint32_t bytes_to_write = prtd->pcm_count;
avail = prtd->bytes_received - prtd->bytes_sent;
if (avail < prtd->pcm_count)
bytes_to_write = avail;
q6asm_write_async(prtd->audio_client, prtd->stream_id,
bytes_to_write, 0, 0, wflags);
prtd->bytes_sent += bytes_to_write;
}
spin_unlock_irqrestore(&prtd->lock, flags); spin_unlock_irqrestore(&prtd->lock, flags);
return count; return count;
...@@ -954,12 +1173,13 @@ static struct snd_compress_ops q6asm_dai_compress_ops = { ...@@ -954,12 +1173,13 @@ static struct snd_compress_ops q6asm_dai_compress_ops = {
.open = q6asm_dai_compr_open, .open = q6asm_dai_compr_open,
.free = q6asm_dai_compr_free, .free = q6asm_dai_compr_free,
.set_params = q6asm_dai_compr_set_params, .set_params = q6asm_dai_compr_set_params,
.set_metadata = q6asm_dai_compr_set_metadata,
.pointer = q6asm_dai_compr_pointer, .pointer = q6asm_dai_compr_pointer,
.trigger = q6asm_dai_compr_trigger, .trigger = q6asm_dai_compr_trigger,
.get_caps = q6asm_dai_compr_get_caps, .get_caps = q6asm_dai_compr_get_caps,
.get_codec_caps = q6asm_dai_compr_get_codec_caps, .get_codec_caps = q6asm_dai_compr_get_codec_caps,
.mmap = q6asm_dai_compr_mmap, .mmap = q6asm_dai_compr_mmap,
.ack = q6asm_dai_compr_ack, .copy = q6asm_compr_copy,
}; };
static int q6asm_dai_pcm_new(struct snd_soc_component *component, static int q6asm_dai_pcm_new(struct snd_soc_component *component,
......
...@@ -51,6 +51,8 @@ ...@@ -51,6 +51,8 @@
#define ASM_STREAM_CMD_OPEN_READWRITE_V2 0x00010D8D #define ASM_STREAM_CMD_OPEN_READWRITE_V2 0x00010D8D
#define ASM_MEDIA_FMT_ALAC 0x00012f31 #define ASM_MEDIA_FMT_ALAC 0x00012f31
#define ASM_MEDIA_FMT_APE 0x00012f32 #define ASM_MEDIA_FMT_APE 0x00012f32
#define ASM_DATA_CMD_REMOVE_INITIAL_SILENCE 0x00010D67
#define ASM_DATA_CMD_REMOVE_TRAILING_SILENCE 0x00010D68
#define ASM_LEGACY_STREAM_SESSION 0 #define ASM_LEGACY_STREAM_SESSION 0
...@@ -270,7 +272,6 @@ struct audio_client { ...@@ -270,7 +272,6 @@ struct audio_client {
wait_queue_head_t cmd_wait; wait_queue_head_t cmd_wait;
struct aprv2_ibasic_rsp_result_t result; struct aprv2_ibasic_rsp_result_t result;
int perf_mode; int perf_mode;
int stream_id;
struct q6asm *q6asm; struct q6asm *q6asm;
struct device *dev; struct device *dev;
}; };
...@@ -640,6 +641,8 @@ static int32_t q6asm_stream_callback(struct apr_device *adev, ...@@ -640,6 +641,8 @@ static int32_t q6asm_stream_callback(struct apr_device *adev,
case ASM_STREAM_CMD_OPEN_READWRITE_V2: case ASM_STREAM_CMD_OPEN_READWRITE_V2:
case ASM_STREAM_CMD_SET_ENCDEC_PARAM: case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
case ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2: case ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2:
case ASM_DATA_CMD_REMOVE_INITIAL_SILENCE:
case ASM_DATA_CMD_REMOVE_TRAILING_SILENCE:
if (result->status != 0) { if (result->status != 0) {
dev_err(ac->dev, dev_err(ac->dev,
"cmd = 0x%x returned error = 0x%x\n", "cmd = 0x%x returned error = 0x%x\n",
...@@ -671,6 +674,7 @@ static int32_t q6asm_stream_callback(struct apr_device *adev, ...@@ -671,6 +674,7 @@ static int32_t q6asm_stream_callback(struct apr_device *adev,
if (ac->io_mode & ASM_SYNC_IO_MODE) { if (ac->io_mode & ASM_SYNC_IO_MODE) {
phys_addr_t phys; phys_addr_t phys;
unsigned long flags; unsigned long flags;
int token = hdr->token & ASM_WRITE_TOKEN_MASK;
spin_lock_irqsave(&ac->lock, flags); spin_lock_irqsave(&ac->lock, flags);
...@@ -682,12 +686,12 @@ static int32_t q6asm_stream_callback(struct apr_device *adev, ...@@ -682,12 +686,12 @@ static int32_t q6asm_stream_callback(struct apr_device *adev,
goto done; goto done;
} }
phys = port->buf[hdr->token].phys; phys = port->buf[token].phys;
if (lower_32_bits(phys) != result->opcode || if (lower_32_bits(phys) != result->opcode ||
upper_32_bits(phys) != result->status) { upper_32_bits(phys) != result->status) {
dev_err(ac->dev, "Expected addr %pa\n", dev_err(ac->dev, "Expected addr %pa\n",
&port->buf[hdr->token].phys); &port->buf[token].phys);
spin_unlock_irqrestore(&ac->lock, flags); spin_unlock_irqrestore(&ac->lock, flags);
ret = -EINVAL; ret = -EINVAL;
goto done; goto done;
...@@ -828,21 +832,21 @@ EXPORT_SYMBOL_GPL(q6asm_get_session_id); ...@@ -828,21 +832,21 @@ EXPORT_SYMBOL_GPL(q6asm_get_session_id);
* @dev: Pointer to asm child device. * @dev: Pointer to asm child device.
* @cb: event callback. * @cb: event callback.
* @priv: private data associated with this client. * @priv: private data associated with this client.
* @stream_id: stream id * @session_id: session id
* @perf_mode: performace mode for this client * @perf_mode: performace mode for this client
* *
* Return: Will be an error pointer on error or a valid audio client * Return: Will be an error pointer on error or a valid audio client
* on success. * on success.
*/ */
struct audio_client *q6asm_audio_client_alloc(struct device *dev, q6asm_cb cb, struct audio_client *q6asm_audio_client_alloc(struct device *dev, q6asm_cb cb,
void *priv, int stream_id, void *priv, int session_id,
int perf_mode) int perf_mode)
{ {
struct q6asm *a = dev_get_drvdata(dev->parent); struct q6asm *a = dev_get_drvdata(dev->parent);
struct audio_client *ac; struct audio_client *ac;
unsigned long flags; unsigned long flags;
ac = q6asm_get_audio_client(a, stream_id + 1); ac = q6asm_get_audio_client(a, session_id + 1);
if (ac) { if (ac) {
dev_err(dev, "Audio Client already active\n"); dev_err(dev, "Audio Client already active\n");
return ac; return ac;
...@@ -853,17 +857,15 @@ struct audio_client *q6asm_audio_client_alloc(struct device *dev, q6asm_cb cb, ...@@ -853,17 +857,15 @@ struct audio_client *q6asm_audio_client_alloc(struct device *dev, q6asm_cb cb,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
spin_lock_irqsave(&a->slock, flags); spin_lock_irqsave(&a->slock, flags);
a->session[stream_id + 1] = ac; a->session[session_id + 1] = ac;
spin_unlock_irqrestore(&a->slock, flags); spin_unlock_irqrestore(&a->slock, flags);
ac->session = stream_id + 1; ac->session = session_id + 1;
ac->cb = cb; ac->cb = cb;
ac->dev = dev; ac->dev = dev;
ac->q6asm = a; ac->q6asm = a;
ac->priv = priv; ac->priv = priv;
ac->io_mode = ASM_SYNC_IO_MODE; ac->io_mode = ASM_SYNC_IO_MODE;
ac->perf_mode = perf_mode; ac->perf_mode = perf_mode;
/* DSP expects stream id from 1 */
ac->stream_id = 1;
ac->adev = a->adev; ac->adev = a->adev;
kref_init(&ac->refcount); kref_init(&ac->refcount);
...@@ -919,8 +921,9 @@ static int q6asm_ac_send_cmd_sync(struct audio_client *ac, struct apr_pkt *pkt) ...@@ -919,8 +921,9 @@ static int q6asm_ac_send_cmd_sync(struct audio_client *ac, struct apr_pkt *pkt)
* *
* Return: Will be an negative value on error or zero on success * Return: Will be an negative value on error or zero on success
*/ */
int q6asm_open_write(struct audio_client *ac, uint32_t format, int q6asm_open_write(struct audio_client *ac, uint32_t stream_id,
u32 codec_profile, uint16_t bits_per_sample) uint32_t format, u32 codec_profile,
uint16_t bits_per_sample, bool is_gapless)
{ {
struct asm_stream_cmd_open_write_v3 *open; struct asm_stream_cmd_open_write_v3 *open;
struct apr_pkt *pkt; struct apr_pkt *pkt;
...@@ -935,11 +938,13 @@ int q6asm_open_write(struct audio_client *ac, uint32_t format, ...@@ -935,11 +938,13 @@ int q6asm_open_write(struct audio_client *ac, uint32_t format,
pkt = p; pkt = p;
open = p + APR_HDR_SIZE; open = p + APR_HDR_SIZE;
q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, ac->stream_id); q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, stream_id);
pkt->hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V3; pkt->hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V3;
open->mode_flags = 0x00; open->mode_flags = 0x00;
open->mode_flags |= ASM_LEGACY_STREAM_SESSION; open->mode_flags |= ASM_LEGACY_STREAM_SESSION;
if (is_gapless)
open->mode_flags |= BIT(ASM_SHIFT_GAPLESS_MODE_FLAG);
/* source endpoint : matrix */ /* source endpoint : matrix */
open->sink_endpointype = ASM_END_POINT_DEVICE_MATRIX; open->sink_endpointype = ASM_END_POINT_DEVICE_MATRIX;
...@@ -998,8 +1003,9 @@ int q6asm_open_write(struct audio_client *ac, uint32_t format, ...@@ -998,8 +1003,9 @@ int q6asm_open_write(struct audio_client *ac, uint32_t format,
} }
EXPORT_SYMBOL_GPL(q6asm_open_write); EXPORT_SYMBOL_GPL(q6asm_open_write);
static int __q6asm_run(struct audio_client *ac, uint32_t flags, static int __q6asm_run(struct audio_client *ac, uint32_t stream_id,
uint32_t msw_ts, uint32_t lsw_ts, bool wait) uint32_t flags, uint32_t msw_ts, uint32_t lsw_ts,
bool wait)
{ {
struct asm_session_cmd_run_v2 *run; struct asm_session_cmd_run_v2 *run;
struct apr_pkt *pkt; struct apr_pkt *pkt;
...@@ -1014,7 +1020,7 @@ static int __q6asm_run(struct audio_client *ac, uint32_t flags, ...@@ -1014,7 +1020,7 @@ static int __q6asm_run(struct audio_client *ac, uint32_t flags,
pkt = p; pkt = p;
run = p + APR_HDR_SIZE; run = p + APR_HDR_SIZE;
q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, ac->stream_id); q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, stream_id);
pkt->hdr.opcode = ASM_SESSION_CMD_RUN_V2; pkt->hdr.opcode = ASM_SESSION_CMD_RUN_V2;
run->flags = flags; run->flags = flags;
...@@ -1042,10 +1048,10 @@ static int __q6asm_run(struct audio_client *ac, uint32_t flags, ...@@ -1042,10 +1048,10 @@ static int __q6asm_run(struct audio_client *ac, uint32_t flags,
* *
* Return: Will be an negative value on error or zero on success * Return: Will be an negative value on error or zero on success
*/ */
int q6asm_run(struct audio_client *ac, uint32_t flags, int q6asm_run(struct audio_client *ac, uint32_t stream_id, uint32_t flags,
uint32_t msw_ts, uint32_t lsw_ts) uint32_t msw_ts, uint32_t lsw_ts)
{ {
return __q6asm_run(ac, flags, msw_ts, lsw_ts, true); return __q6asm_run(ac, stream_id, flags, msw_ts, lsw_ts, true);
} }
EXPORT_SYMBOL_GPL(q6asm_run); EXPORT_SYMBOL_GPL(q6asm_run);
...@@ -1053,16 +1059,17 @@ EXPORT_SYMBOL_GPL(q6asm_run); ...@@ -1053,16 +1059,17 @@ EXPORT_SYMBOL_GPL(q6asm_run);
* q6asm_run_nowait() - start the audio client withou blocking * q6asm_run_nowait() - start the audio client withou blocking
* *
* @ac: audio client pointer * @ac: audio client pointer
* @stream_id: stream id
* @flags: flags associated with write * @flags: flags associated with write
* @msw_ts: timestamp msw * @msw_ts: timestamp msw
* @lsw_ts: timestamp lsw * @lsw_ts: timestamp lsw
* *
* Return: Will be an negative value on error or zero on success * Return: Will be an negative value on error or zero on success
*/ */
int q6asm_run_nowait(struct audio_client *ac, uint32_t flags, int q6asm_run_nowait(struct audio_client *ac, uint32_t stream_id,
uint32_t msw_ts, uint32_t lsw_ts) uint32_t flags, uint32_t msw_ts, uint32_t lsw_ts)
{ {
return __q6asm_run(ac, flags, msw_ts, lsw_ts, false); return __q6asm_run(ac, stream_id, flags, msw_ts, lsw_ts, false);
} }
EXPORT_SYMBOL_GPL(q6asm_run_nowait); EXPORT_SYMBOL_GPL(q6asm_run_nowait);
...@@ -1070,6 +1077,7 @@ EXPORT_SYMBOL_GPL(q6asm_run_nowait); ...@@ -1070,6 +1077,7 @@ EXPORT_SYMBOL_GPL(q6asm_run_nowait);
* q6asm_media_format_block_multi_ch_pcm() - setup pcm configuration * q6asm_media_format_block_multi_ch_pcm() - setup pcm configuration
* *
* @ac: audio client pointer * @ac: audio client pointer
* @stream_id: stream id
* @rate: audio sample rate * @rate: audio sample rate
* @channels: number of audio channels. * @channels: number of audio channels.
* @channel_map: channel map pointer * @channel_map: channel map pointer
...@@ -1078,6 +1086,7 @@ EXPORT_SYMBOL_GPL(q6asm_run_nowait); ...@@ -1078,6 +1086,7 @@ EXPORT_SYMBOL_GPL(q6asm_run_nowait);
* Return: Will be an negative value on error or zero on success * Return: Will be an negative value on error or zero on success
*/ */
int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac, int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
uint32_t stream_id,
uint32_t rate, uint32_t channels, uint32_t rate, uint32_t channels,
u8 channel_map[PCM_MAX_NUM_CHANNEL], u8 channel_map[PCM_MAX_NUM_CHANNEL],
uint16_t bits_per_sample) uint16_t bits_per_sample)
...@@ -1096,7 +1105,7 @@ int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac, ...@@ -1096,7 +1105,7 @@ int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
pkt = p; pkt = p;
fmt = p + APR_HDR_SIZE; fmt = p + APR_HDR_SIZE;
q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, ac->stream_id); q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, stream_id);
pkt->hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2; pkt->hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
fmt->fmt_blk.fmt_blk_size = sizeof(*fmt) - sizeof(fmt->fmt_blk); fmt->fmt_blk.fmt_blk_size = sizeof(*fmt) - sizeof(fmt->fmt_blk);
...@@ -1125,8 +1134,8 @@ int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac, ...@@ -1125,8 +1134,8 @@ int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
} }
EXPORT_SYMBOL_GPL(q6asm_media_format_block_multi_ch_pcm); EXPORT_SYMBOL_GPL(q6asm_media_format_block_multi_ch_pcm);
int q6asm_stream_media_format_block_flac(struct audio_client *ac, int q6asm_stream_media_format_block_flac(struct audio_client *ac,
uint32_t stream_id,
struct q6asm_flac_cfg *cfg) struct q6asm_flac_cfg *cfg)
{ {
struct asm_flac_fmt_blk_v2 *fmt; struct asm_flac_fmt_blk_v2 *fmt;
...@@ -1142,7 +1151,7 @@ int q6asm_stream_media_format_block_flac(struct audio_client *ac, ...@@ -1142,7 +1151,7 @@ int q6asm_stream_media_format_block_flac(struct audio_client *ac,
pkt = p; pkt = p;
fmt = p + APR_HDR_SIZE; fmt = p + APR_HDR_SIZE;
q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, ac->stream_id); q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, stream_id);
pkt->hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2; pkt->hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
fmt->fmt_blk.fmt_blk_size = sizeof(*fmt) - sizeof(fmt->fmt_blk); fmt->fmt_blk.fmt_blk_size = sizeof(*fmt) - sizeof(fmt->fmt_blk);
...@@ -1163,6 +1172,7 @@ int q6asm_stream_media_format_block_flac(struct audio_client *ac, ...@@ -1163,6 +1172,7 @@ int q6asm_stream_media_format_block_flac(struct audio_client *ac,
EXPORT_SYMBOL_GPL(q6asm_stream_media_format_block_flac); EXPORT_SYMBOL_GPL(q6asm_stream_media_format_block_flac);
int q6asm_stream_media_format_block_wma_v9(struct audio_client *ac, int q6asm_stream_media_format_block_wma_v9(struct audio_client *ac,
uint32_t stream_id,
struct q6asm_wma_cfg *cfg) struct q6asm_wma_cfg *cfg)
{ {
struct asm_wmastdv9_fmt_blk_v2 *fmt; struct asm_wmastdv9_fmt_blk_v2 *fmt;
...@@ -1178,7 +1188,7 @@ int q6asm_stream_media_format_block_wma_v9(struct audio_client *ac, ...@@ -1178,7 +1188,7 @@ int q6asm_stream_media_format_block_wma_v9(struct audio_client *ac,
pkt = p; pkt = p;
fmt = p + APR_HDR_SIZE; fmt = p + APR_HDR_SIZE;
q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, ac->stream_id); q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, stream_id);
pkt->hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2; pkt->hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
fmt->fmt_blk.fmt_blk_size = sizeof(*fmt) - sizeof(fmt->fmt_blk); fmt->fmt_blk.fmt_blk_size = sizeof(*fmt) - sizeof(fmt->fmt_blk);
...@@ -1200,6 +1210,7 @@ int q6asm_stream_media_format_block_wma_v9(struct audio_client *ac, ...@@ -1200,6 +1210,7 @@ int q6asm_stream_media_format_block_wma_v9(struct audio_client *ac,
EXPORT_SYMBOL_GPL(q6asm_stream_media_format_block_wma_v9); EXPORT_SYMBOL_GPL(q6asm_stream_media_format_block_wma_v9);
int q6asm_stream_media_format_block_wma_v10(struct audio_client *ac, int q6asm_stream_media_format_block_wma_v10(struct audio_client *ac,
uint32_t stream_id,
struct q6asm_wma_cfg *cfg) struct q6asm_wma_cfg *cfg)
{ {
struct asm_wmaprov10_fmt_blk_v2 *fmt; struct asm_wmaprov10_fmt_blk_v2 *fmt;
...@@ -1215,7 +1226,7 @@ int q6asm_stream_media_format_block_wma_v10(struct audio_client *ac, ...@@ -1215,7 +1226,7 @@ int q6asm_stream_media_format_block_wma_v10(struct audio_client *ac,
pkt = p; pkt = p;
fmt = p + APR_HDR_SIZE; fmt = p + APR_HDR_SIZE;
q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, ac->stream_id); q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, stream_id);
pkt->hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2; pkt->hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
fmt->fmt_blk.fmt_blk_size = sizeof(*fmt) - sizeof(fmt->fmt_blk); fmt->fmt_blk.fmt_blk_size = sizeof(*fmt) - sizeof(fmt->fmt_blk);
...@@ -1238,6 +1249,7 @@ int q6asm_stream_media_format_block_wma_v10(struct audio_client *ac, ...@@ -1238,6 +1249,7 @@ int q6asm_stream_media_format_block_wma_v10(struct audio_client *ac,
EXPORT_SYMBOL_GPL(q6asm_stream_media_format_block_wma_v10); EXPORT_SYMBOL_GPL(q6asm_stream_media_format_block_wma_v10);
int q6asm_stream_media_format_block_alac(struct audio_client *ac, int q6asm_stream_media_format_block_alac(struct audio_client *ac,
uint32_t stream_id,
struct q6asm_alac_cfg *cfg) struct q6asm_alac_cfg *cfg)
{ {
struct asm_alac_fmt_blk_v2 *fmt; struct asm_alac_fmt_blk_v2 *fmt;
...@@ -1253,7 +1265,7 @@ int q6asm_stream_media_format_block_alac(struct audio_client *ac, ...@@ -1253,7 +1265,7 @@ int q6asm_stream_media_format_block_alac(struct audio_client *ac,
pkt = p; pkt = p;
fmt = p + APR_HDR_SIZE; fmt = p + APR_HDR_SIZE;
q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, ac->stream_id); q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, stream_id);
pkt->hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2; pkt->hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
fmt->fmt_blk.fmt_blk_size = sizeof(*fmt) - sizeof(fmt->fmt_blk); fmt->fmt_blk.fmt_blk_size = sizeof(*fmt) - sizeof(fmt->fmt_blk);
...@@ -1279,6 +1291,7 @@ int q6asm_stream_media_format_block_alac(struct audio_client *ac, ...@@ -1279,6 +1291,7 @@ int q6asm_stream_media_format_block_alac(struct audio_client *ac,
EXPORT_SYMBOL_GPL(q6asm_stream_media_format_block_alac); EXPORT_SYMBOL_GPL(q6asm_stream_media_format_block_alac);
int q6asm_stream_media_format_block_ape(struct audio_client *ac, int q6asm_stream_media_format_block_ape(struct audio_client *ac,
uint32_t stream_id,
struct q6asm_ape_cfg *cfg) struct q6asm_ape_cfg *cfg)
{ {
struct asm_ape_fmt_blk_v2 *fmt; struct asm_ape_fmt_blk_v2 *fmt;
...@@ -1294,7 +1307,7 @@ int q6asm_stream_media_format_block_ape(struct audio_client *ac, ...@@ -1294,7 +1307,7 @@ int q6asm_stream_media_format_block_ape(struct audio_client *ac,
pkt = p; pkt = p;
fmt = p + APR_HDR_SIZE; fmt = p + APR_HDR_SIZE;
q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, ac->stream_id); q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, stream_id);
pkt->hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2; pkt->hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
fmt->fmt_blk.fmt_blk_size = sizeof(*fmt) - sizeof(fmt->fmt_blk); fmt->fmt_blk.fmt_blk_size = sizeof(*fmt) - sizeof(fmt->fmt_blk);
...@@ -1317,10 +1330,60 @@ int q6asm_stream_media_format_block_ape(struct audio_client *ac, ...@@ -1317,10 +1330,60 @@ int q6asm_stream_media_format_block_ape(struct audio_client *ac,
} }
EXPORT_SYMBOL_GPL(q6asm_stream_media_format_block_ape); EXPORT_SYMBOL_GPL(q6asm_stream_media_format_block_ape);
static int q6asm_stream_remove_silence(struct audio_client *ac, uint32_t stream_id,
uint32_t cmd,
uint32_t num_samples)
{
uint32_t *samples;
struct apr_pkt *pkt;
void *p;
int rc, pkt_size;
pkt_size = APR_HDR_SIZE + sizeof(uint32_t);
p = kzalloc(pkt_size, GFP_ATOMIC);
if (!p)
return -ENOMEM;
pkt = p;
samples = p + APR_HDR_SIZE;
q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, stream_id);
pkt->hdr.opcode = cmd;
*samples = num_samples;
rc = apr_send_pkt(ac->adev, pkt);
if (rc == pkt_size)
rc = 0;
kfree(pkt);
return rc;
}
int q6asm_stream_remove_initial_silence(struct audio_client *ac,
uint32_t stream_id,
uint32_t initial_samples)
{
return q6asm_stream_remove_silence(ac, stream_id,
ASM_DATA_CMD_REMOVE_INITIAL_SILENCE,
initial_samples);
}
EXPORT_SYMBOL_GPL(q6asm_stream_remove_initial_silence);
int q6asm_stream_remove_trailing_silence(struct audio_client *ac, uint32_t stream_id,
uint32_t trailing_samples)
{
return q6asm_stream_remove_silence(ac, stream_id,
ASM_DATA_CMD_REMOVE_TRAILING_SILENCE,
trailing_samples);
}
EXPORT_SYMBOL_GPL(q6asm_stream_remove_trailing_silence);
/** /**
* q6asm_enc_cfg_blk_pcm_format_support() - setup pcm configuration for capture * q6asm_enc_cfg_blk_pcm_format_support() - setup pcm configuration for capture
* *
* @ac: audio client pointer * @ac: audio client pointer
* @stream_id: stream id
* @rate: audio sample rate * @rate: audio sample rate
* @channels: number of audio channels. * @channels: number of audio channels.
* @bits_per_sample: bits per sample * @bits_per_sample: bits per sample
...@@ -1328,7 +1391,9 @@ EXPORT_SYMBOL_GPL(q6asm_stream_media_format_block_ape); ...@@ -1328,7 +1391,9 @@ EXPORT_SYMBOL_GPL(q6asm_stream_media_format_block_ape);
* Return: Will be an negative value on error or zero on success * Return: Will be an negative value on error or zero on success
*/ */
int q6asm_enc_cfg_blk_pcm_format_support(struct audio_client *ac, int q6asm_enc_cfg_blk_pcm_format_support(struct audio_client *ac,
uint32_t rate, uint32_t channels, uint16_t bits_per_sample) uint32_t stream_id, uint32_t rate,
uint32_t channels,
uint16_t bits_per_sample)
{ {
struct asm_multi_channel_pcm_enc_cfg_v2 *enc_cfg; struct asm_multi_channel_pcm_enc_cfg_v2 *enc_cfg;
struct apr_pkt *pkt; struct apr_pkt *pkt;
...@@ -1344,7 +1409,7 @@ int q6asm_enc_cfg_blk_pcm_format_support(struct audio_client *ac, ...@@ -1344,7 +1409,7 @@ int q6asm_enc_cfg_blk_pcm_format_support(struct audio_client *ac,
pkt = p; pkt = p;
enc_cfg = p + APR_HDR_SIZE; enc_cfg = p + APR_HDR_SIZE;
q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, ac->stream_id); q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, stream_id);
pkt->hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM; pkt->hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
enc_cfg->encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2; enc_cfg->encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
...@@ -1376,10 +1441,11 @@ EXPORT_SYMBOL_GPL(q6asm_enc_cfg_blk_pcm_format_support); ...@@ -1376,10 +1441,11 @@ EXPORT_SYMBOL_GPL(q6asm_enc_cfg_blk_pcm_format_support);
* q6asm_read() - read data of period size from audio client * q6asm_read() - read data of period size from audio client
* *
* @ac: audio client pointer * @ac: audio client pointer
* @stream_id: stream id
* *
* Return: Will be an negative value on error or zero on success * Return: Will be an negative value on error or zero on success
*/ */
int q6asm_read(struct audio_client *ac) int q6asm_read(struct audio_client *ac, uint32_t stream_id)
{ {
struct asm_data_cmd_read_v2 *read; struct asm_data_cmd_read_v2 *read;
struct audio_port_data *port; struct audio_port_data *port;
...@@ -1400,7 +1466,7 @@ int q6asm_read(struct audio_client *ac) ...@@ -1400,7 +1466,7 @@ int q6asm_read(struct audio_client *ac)
spin_lock_irqsave(&ac->lock, flags); spin_lock_irqsave(&ac->lock, flags);
port = &ac->port[SNDRV_PCM_STREAM_CAPTURE]; port = &ac->port[SNDRV_PCM_STREAM_CAPTURE];
q6asm_add_hdr(ac, &pkt->hdr, pkt_size, false, ac->stream_id); q6asm_add_hdr(ac, &pkt->hdr, pkt_size, false, stream_id);
ab = &port->buf[port->dsp_buf]; ab = &port->buf[port->dsp_buf];
pkt->hdr.opcode = ASM_DATA_CMD_READ_V2; pkt->hdr.opcode = ASM_DATA_CMD_READ_V2;
read->buf_addr_lsw = lower_32_bits(ab->phys); read->buf_addr_lsw = lower_32_bits(ab->phys);
...@@ -1428,7 +1494,7 @@ int q6asm_read(struct audio_client *ac) ...@@ -1428,7 +1494,7 @@ int q6asm_read(struct audio_client *ac)
} }
EXPORT_SYMBOL_GPL(q6asm_read); EXPORT_SYMBOL_GPL(q6asm_read);
static int __q6asm_open_read(struct audio_client *ac, static int __q6asm_open_read(struct audio_client *ac, uint32_t stream_id,
uint32_t format, uint16_t bits_per_sample) uint32_t format, uint16_t bits_per_sample)
{ {
struct asm_stream_cmd_open_read_v3 *open; struct asm_stream_cmd_open_read_v3 *open;
...@@ -1444,7 +1510,7 @@ static int __q6asm_open_read(struct audio_client *ac, ...@@ -1444,7 +1510,7 @@ static int __q6asm_open_read(struct audio_client *ac,
pkt = p; pkt = p;
open = p + APR_HDR_SIZE; open = p + APR_HDR_SIZE;
q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, ac->stream_id); q6asm_add_hdr(ac, &pkt->hdr, pkt_size, true, stream_id);
pkt->hdr.opcode = ASM_STREAM_CMD_OPEN_READ_V3; pkt->hdr.opcode = ASM_STREAM_CMD_OPEN_READ_V3;
/* Stream prio : High, provide meta info with encoded frames */ /* Stream prio : High, provide meta info with encoded frames */
open->src_endpointype = ASM_END_POINT_DEVICE_MATRIX; open->src_endpointype = ASM_END_POINT_DEVICE_MATRIX;
...@@ -1475,15 +1541,16 @@ static int __q6asm_open_read(struct audio_client *ac, ...@@ -1475,15 +1541,16 @@ static int __q6asm_open_read(struct audio_client *ac,
* q6asm_open_read() - Open audio client for reading * q6asm_open_read() - Open audio client for reading
* *
* @ac: audio client pointer * @ac: audio client pointer
* @stream_id: stream id
* @format: audio sample format * @format: audio sample format
* @bits_per_sample: bits per sample * @bits_per_sample: bits per sample
* *
* Return: Will be an negative value on error or zero on success * Return: Will be an negative value on error or zero on success
*/ */
int q6asm_open_read(struct audio_client *ac, uint32_t format, int q6asm_open_read(struct audio_client *ac, uint32_t stream_id,
uint16_t bits_per_sample) uint32_t format, uint16_t bits_per_sample)
{ {
return __q6asm_open_read(ac, format, bits_per_sample); return __q6asm_open_read(ac, stream_id, format, bits_per_sample);
} }
EXPORT_SYMBOL_GPL(q6asm_open_read); EXPORT_SYMBOL_GPL(q6asm_open_read);
...@@ -1491,6 +1558,7 @@ EXPORT_SYMBOL_GPL(q6asm_open_read); ...@@ -1491,6 +1558,7 @@ EXPORT_SYMBOL_GPL(q6asm_open_read);
* q6asm_write_async() - non blocking write * q6asm_write_async() - non blocking write
* *
* @ac: audio client pointer * @ac: audio client pointer
* @stream_id: stream id
* @len: length in bytes * @len: length in bytes
* @msw_ts: timestamp msw * @msw_ts: timestamp msw
* @lsw_ts: timestamp lsw * @lsw_ts: timestamp lsw
...@@ -1498,8 +1566,8 @@ EXPORT_SYMBOL_GPL(q6asm_open_read); ...@@ -1498,8 +1566,8 @@ EXPORT_SYMBOL_GPL(q6asm_open_read);
* *
* Return: Will be an negative value on error or zero on success * Return: Will be an negative value on error or zero on success
*/ */
int q6asm_write_async(struct audio_client *ac, uint32_t len, uint32_t msw_ts, int q6asm_write_async(struct audio_client *ac, uint32_t stream_id, uint32_t len,
uint32_t lsw_ts, uint32_t wflags) uint32_t msw_ts, uint32_t lsw_ts, uint32_t wflags)
{ {
struct asm_data_cmd_write_v2 *write; struct asm_data_cmd_write_v2 *write;
struct audio_port_data *port; struct audio_port_data *port;
...@@ -1520,10 +1588,10 @@ int q6asm_write_async(struct audio_client *ac, uint32_t len, uint32_t msw_ts, ...@@ -1520,10 +1588,10 @@ int q6asm_write_async(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
spin_lock_irqsave(&ac->lock, flags); spin_lock_irqsave(&ac->lock, flags);
port = &ac->port[SNDRV_PCM_STREAM_PLAYBACK]; port = &ac->port[SNDRV_PCM_STREAM_PLAYBACK];
q6asm_add_hdr(ac, &pkt->hdr, pkt_size, false, ac->stream_id); q6asm_add_hdr(ac, &pkt->hdr, pkt_size, false, stream_id);
ab = &port->buf[port->dsp_buf]; ab = &port->buf[port->dsp_buf];
pkt->hdr.token = port->dsp_buf; pkt->hdr.token = port->dsp_buf | (len << ASM_WRITE_TOKEN_LEN_SHIFT);
pkt->hdr.opcode = ASM_DATA_CMD_WRITE_V2; pkt->hdr.opcode = ASM_DATA_CMD_WRITE_V2;
write->buf_addr_lsw = lower_32_bits(ab->phys); write->buf_addr_lsw = lower_32_bits(ab->phys);
write->buf_addr_msw = upper_32_bits(ab->phys); write->buf_addr_msw = upper_32_bits(ab->phys);
...@@ -1534,10 +1602,7 @@ int q6asm_write_async(struct audio_client *ac, uint32_t len, uint32_t msw_ts, ...@@ -1534,10 +1602,7 @@ int q6asm_write_async(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
write->mem_map_handle = write->mem_map_handle =
ac->port[SNDRV_PCM_STREAM_PLAYBACK].mem_map_handle; ac->port[SNDRV_PCM_STREAM_PLAYBACK].mem_map_handle;
if (wflags == NO_TIMESTAMP) write->flags = wflags;
write->flags = (wflags & 0x800000FF);
else
write->flags = (0x80000000 | wflags);
port->dsp_buf++; port->dsp_buf++;
...@@ -1567,9 +1632,9 @@ static void q6asm_reset_buf_state(struct audio_client *ac) ...@@ -1567,9 +1632,9 @@ static void q6asm_reset_buf_state(struct audio_client *ac)
spin_unlock_irqrestore(&ac->lock, flags); spin_unlock_irqrestore(&ac->lock, flags);
} }
static int __q6asm_cmd(struct audio_client *ac, int cmd, bool wait) static int __q6asm_cmd(struct audio_client *ac, uint32_t stream_id, int cmd,
bool wait)
{ {
int stream_id = ac->stream_id;
struct apr_pkt pkt; struct apr_pkt pkt;
int rc; int rc;
...@@ -1616,13 +1681,14 @@ static int __q6asm_cmd(struct audio_client *ac, int cmd, bool wait) ...@@ -1616,13 +1681,14 @@ static int __q6asm_cmd(struct audio_client *ac, int cmd, bool wait)
* q6asm_cmd() - run cmd on audio client * q6asm_cmd() - run cmd on audio client
* *
* @ac: audio client pointer * @ac: audio client pointer
* @stream_id: stream id
* @cmd: command to run on audio client. * @cmd: command to run on audio client.
* *
* Return: Will be an negative value on error or zero on success * Return: Will be an negative value on error or zero on success
*/ */
int q6asm_cmd(struct audio_client *ac, int cmd) int q6asm_cmd(struct audio_client *ac, uint32_t stream_id, int cmd)
{ {
return __q6asm_cmd(ac, cmd, true); return __q6asm_cmd(ac, stream_id, cmd, true);
} }
EXPORT_SYMBOL_GPL(q6asm_cmd); EXPORT_SYMBOL_GPL(q6asm_cmd);
...@@ -1630,13 +1696,14 @@ EXPORT_SYMBOL_GPL(q6asm_cmd); ...@@ -1630,13 +1696,14 @@ EXPORT_SYMBOL_GPL(q6asm_cmd);
* q6asm_cmd_nowait() - non blocking, run cmd on audio client * q6asm_cmd_nowait() - non blocking, run cmd on audio client
* *
* @ac: audio client pointer * @ac: audio client pointer
* @stream_id: stream id
* @cmd: command to run on audio client. * @cmd: command to run on audio client.
* *
* Return: Will be an negative value on error or zero on success * Return: Will be an negative value on error or zero on success
*/ */
int q6asm_cmd_nowait(struct audio_client *ac, int cmd) int q6asm_cmd_nowait(struct audio_client *ac, uint32_t stream_id, int cmd)
{ {
return __q6asm_cmd(ac, cmd, false); return __q6asm_cmd(ac, stream_id, cmd, false);
} }
EXPORT_SYMBOL_GPL(q6asm_cmd_nowait); EXPORT_SYMBOL_GPL(q6asm_cmd_nowait);
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
#define ASM_CLIENT_EVENT_CMD_RUN_DONE 0x1008 #define ASM_CLIENT_EVENT_CMD_RUN_DONE 0x1008
#define ASM_CLIENT_EVENT_DATA_WRITE_DONE 0x1009 #define ASM_CLIENT_EVENT_DATA_WRITE_DONE 0x1009
#define ASM_CLIENT_EVENT_DATA_READ_DONE 0x100a #define ASM_CLIENT_EVENT_DATA_READ_DONE 0x100a
#define ASM_WRITE_TOKEN_MASK GENMASK(15, 0)
#define ASM_WRITE_TOKEN_LEN_MASK GENMASK(31, 16)
#define ASM_WRITE_TOKEN_LEN_SHIFT 16
enum { enum {
LEGACY_PCM_MODE = 0, LEGACY_PCM_MODE = 0,
...@@ -29,8 +32,8 @@ enum { ...@@ -29,8 +32,8 @@ enum {
}; };
#define MAX_SESSIONS 8 #define MAX_SESSIONS 8
#define NO_TIMESTAMP 0xFF00
#define FORMAT_LINEAR_PCM 0x0000 #define FORMAT_LINEAR_PCM 0x0000
#define ASM_LAST_BUFFER_FLAG BIT(30)
struct q6asm_flac_cfg { struct q6asm_flac_cfg {
u32 sample_rate; u32 sample_rate;
...@@ -93,37 +96,53 @@ struct audio_client *q6asm_audio_client_alloc(struct device *dev, ...@@ -93,37 +96,53 @@ struct audio_client *q6asm_audio_client_alloc(struct device *dev,
q6asm_cb cb, void *priv, q6asm_cb cb, void *priv,
int session_id, int perf_mode); int session_id, int perf_mode);
void q6asm_audio_client_free(struct audio_client *ac); void q6asm_audio_client_free(struct audio_client *ac);
int q6asm_write_async(struct audio_client *ac, uint32_t len, uint32_t msw_ts, int q6asm_write_async(struct audio_client *ac, uint32_t stream_id, uint32_t len,
uint32_t lsw_ts, uint32_t flags); uint32_t msw_ts, uint32_t lsw_ts, uint32_t flags);
int q6asm_open_write(struct audio_client *ac, uint32_t format, int q6asm_open_write(struct audio_client *ac, uint32_t stream_id,
u32 codec_profile, uint16_t bits_per_sample); uint32_t format, u32 codec_profile,
uint16_t bits_per_sample, bool is_gapless);
int q6asm_open_read(struct audio_client *ac, uint32_t format, int q6asm_open_read(struct audio_client *ac, uint32_t stream_id,
uint16_t bits_per_sample); uint32_t format, uint16_t bits_per_sample);
int q6asm_enc_cfg_blk_pcm_format_support(struct audio_client *ac, int q6asm_enc_cfg_blk_pcm_format_support(struct audio_client *ac,
uint32_t rate, uint32_t channels, uint16_t bits_per_sample); uint32_t stream_id, uint32_t rate,
int q6asm_read(struct audio_client *ac); uint32_t channels,
uint16_t bits_per_sample);
int q6asm_read(struct audio_client *ac, uint32_t stream_id);
int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac, int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
uint32_t stream_id,
uint32_t rate, uint32_t channels, uint32_t rate, uint32_t channels,
u8 channel_map[PCM_MAX_NUM_CHANNEL], u8 channel_map[PCM_MAX_NUM_CHANNEL],
uint16_t bits_per_sample); uint16_t bits_per_sample);
int q6asm_stream_media_format_block_flac(struct audio_client *ac, int q6asm_stream_media_format_block_flac(struct audio_client *ac,
uint32_t stream_id,
struct q6asm_flac_cfg *cfg); struct q6asm_flac_cfg *cfg);
int q6asm_stream_media_format_block_wma_v9(struct audio_client *ac, int q6asm_stream_media_format_block_wma_v9(struct audio_client *ac,
uint32_t stream_id,
struct q6asm_wma_cfg *cfg); struct q6asm_wma_cfg *cfg);
int q6asm_stream_media_format_block_wma_v10(struct audio_client *ac, int q6asm_stream_media_format_block_wma_v10(struct audio_client *ac,
uint32_t stream_id,
struct q6asm_wma_cfg *cfg); struct q6asm_wma_cfg *cfg);
int q6asm_stream_media_format_block_alac(struct audio_client *ac, int q6asm_stream_media_format_block_alac(struct audio_client *ac,
uint32_t stream_id,
struct q6asm_alac_cfg *cfg); struct q6asm_alac_cfg *cfg);
int q6asm_stream_media_format_block_ape(struct audio_client *ac, int q6asm_stream_media_format_block_ape(struct audio_client *ac,
uint32_t stream_id,
struct q6asm_ape_cfg *cfg); struct q6asm_ape_cfg *cfg);
int q6asm_run(struct audio_client *ac, uint32_t flags, uint32_t msw_ts, int q6asm_run(struct audio_client *ac, uint32_t stream_id, uint32_t flags,
uint32_t lsw_ts); uint32_t msw_ts, uint32_t lsw_ts);
int q6asm_run_nowait(struct audio_client *ac, uint32_t flags, uint32_t msw_ts, int q6asm_run_nowait(struct audio_client *ac, uint32_t stream_id,
uint32_t lsw_ts); uint32_t flags, uint32_t msw_ts, uint32_t lsw_ts);
int q6asm_cmd(struct audio_client *ac, int cmd); int q6asm_stream_remove_initial_silence(struct audio_client *ac,
int q6asm_cmd_nowait(struct audio_client *ac, int cmd); uint32_t stream_id,
uint32_t initial_samples);
int q6asm_stream_remove_trailing_silence(struct audio_client *ac,
uint32_t stream_id,
uint32_t trailing_samples);
int q6asm_cmd(struct audio_client *ac, uint32_t stream_id, int cmd);
int q6asm_cmd_nowait(struct audio_client *ac, uint32_t stream_id, int cmd);
int q6asm_get_session_id(struct audio_client *ac); int q6asm_get_session_id(struct audio_client *ac);
int q6asm_map_memory_regions(unsigned int dir, int q6asm_map_memory_regions(unsigned int dir,
struct audio_client *ac, struct audio_client *ac,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment