0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/device.h>
0013 #include <linux/export.h>
0014 #include <linux/module.h>
0015 #include <linux/types.h>
0016
0017 #include <sound/pcm.h>
0018 #include <sound/sof/stream.h>
0019
0020 #include "ops.h"
0021 #include "sof-priv.h"
0022
0023 struct sof_stream {
0024 size_t posn_offset;
0025 };
0026
0027
0028 int sof_ipc_msg_data(struct snd_sof_dev *sdev,
0029 struct snd_pcm_substream *substream,
0030 void *p, size_t sz)
0031 {
0032 if (!substream || !sdev->stream_box.size) {
0033 snd_sof_dsp_mailbox_read(sdev, sdev->dsp_box.offset, p, sz);
0034 } else {
0035 struct sof_stream *stream = substream->runtime->private_data;
0036
0037
0038 if (!stream)
0039 return -ESTRPIPE;
0040
0041 snd_sof_dsp_mailbox_read(sdev, stream->posn_offset, p, sz);
0042 }
0043
0044 return 0;
0045 }
0046 EXPORT_SYMBOL(sof_ipc_msg_data);
0047
0048 int sof_set_stream_data_offset(struct snd_sof_dev *sdev,
0049 struct snd_pcm_substream *substream,
0050 size_t posn_offset)
0051 {
0052 struct sof_stream *stream = substream->runtime->private_data;
0053
0054
0055 if (posn_offset > sdev->stream_box.size ||
0056 posn_offset % sizeof(struct sof_ipc_stream_posn) != 0)
0057 return -EINVAL;
0058
0059 stream->posn_offset = sdev->stream_box.offset + posn_offset;
0060
0061 dev_dbg(sdev->dev, "pcm: stream dir %d, posn mailbox offset is %zu",
0062 substream->stream, stream->posn_offset);
0063
0064 return 0;
0065 }
0066 EXPORT_SYMBOL(sof_set_stream_data_offset);
0067
0068 int sof_stream_pcm_open(struct snd_sof_dev *sdev,
0069 struct snd_pcm_substream *substream)
0070 {
0071 struct sof_stream *stream = kmalloc(sizeof(*stream), GFP_KERNEL);
0072
0073 if (!stream)
0074 return -ENOMEM;
0075
0076
0077 substream->runtime->private_data = stream;
0078
0079
0080 snd_pcm_hw_constraint_step(substream->runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 4);
0081
0082
0083 snd_pcm_hw_constraint_integer(substream->runtime,
0084 SNDRV_PCM_HW_PARAM_PERIODS);
0085
0086 return 0;
0087 }
0088 EXPORT_SYMBOL(sof_stream_pcm_open);
0089
0090 int sof_stream_pcm_close(struct snd_sof_dev *sdev,
0091 struct snd_pcm_substream *substream)
0092 {
0093 struct sof_stream *stream = substream->runtime->private_data;
0094
0095 substream->runtime->private_data = NULL;
0096 kfree(stream);
0097
0098 return 0;
0099 }
0100 EXPORT_SYMBOL(sof_stream_pcm_close);
0101
0102 MODULE_LICENSE("Dual BSD/GPL");