WIP FPC-III support
[linux/fpc-iii.git] / sound / soc / sof / intel / intel-ipc.c
blobde66f8a82a07a4b197a8f22ed80759e43910fe7b
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2 //
3 // This file is provided under a dual BSD/GPLv2 license. When using or
4 // redistributing this file, you may do so under either license.
5 //
6 // Copyright(c) 2019 Intel Corporation. All rights reserved.
7 //
8 // Authors: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
10 /* Intel-specific SOF IPC code */
12 #include <linux/device.h>
13 #include <linux/export.h>
14 #include <linux/module.h>
15 #include <linux/types.h>
17 #include <sound/pcm.h>
18 #include <sound/sof/stream.h>
20 #include "../ops.h"
21 #include "../sof-priv.h"
23 struct intel_stream {
24 size_t posn_offset;
27 /* Mailbox-based Intel IPC implementation */
28 void intel_ipc_msg_data(struct snd_sof_dev *sdev,
29 struct snd_pcm_substream *substream,
30 void *p, size_t sz)
32 if (!substream || !sdev->stream_box.size) {
33 sof_mailbox_read(sdev, sdev->dsp_box.offset, p, sz);
34 } else {
35 struct intel_stream *stream = substream->runtime->private_data;
37 /* The stream might already be closed */
38 if (stream)
39 sof_mailbox_read(sdev, stream->posn_offset, p, sz);
42 EXPORT_SYMBOL_NS(intel_ipc_msg_data, SND_SOC_SOF_INTEL_HIFI_EP_IPC);
44 int intel_ipc_pcm_params(struct snd_sof_dev *sdev,
45 struct snd_pcm_substream *substream,
46 const struct sof_ipc_pcm_params_reply *reply)
48 struct intel_stream *stream = substream->runtime->private_data;
49 size_t posn_offset = reply->posn_offset;
51 /* check if offset is overflow or it is not aligned */
52 if (posn_offset > sdev->stream_box.size ||
53 posn_offset % sizeof(struct sof_ipc_stream_posn) != 0)
54 return -EINVAL;
56 stream->posn_offset = sdev->stream_box.offset + posn_offset;
58 dev_dbg(sdev->dev, "pcm: stream dir %d, posn mailbox offset is %zu",
59 substream->stream, stream->posn_offset);
61 return 0;
63 EXPORT_SYMBOL_NS(intel_ipc_pcm_params, SND_SOC_SOF_INTEL_HIFI_EP_IPC);
65 int intel_pcm_open(struct snd_sof_dev *sdev,
66 struct snd_pcm_substream *substream)
68 struct intel_stream *stream = kmalloc(sizeof(*stream), GFP_KERNEL);
70 if (!stream)
71 return -ENOMEM;
73 /* binding pcm substream to hda stream */
74 substream->runtime->private_data = stream;
76 /* align to DMA minimum transfer size */
77 snd_pcm_hw_constraint_step(substream->runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 4);
79 /* avoid circular buffer wrap in middle of period */
80 snd_pcm_hw_constraint_integer(substream->runtime,
81 SNDRV_PCM_HW_PARAM_PERIODS);
83 return 0;
85 EXPORT_SYMBOL_NS(intel_pcm_open, SND_SOC_SOF_INTEL_HIFI_EP_IPC);
87 int intel_pcm_close(struct snd_sof_dev *sdev,
88 struct snd_pcm_substream *substream)
90 struct intel_stream *stream = substream->runtime->private_data;
92 substream->runtime->private_data = NULL;
93 kfree(stream);
95 return 0;
97 EXPORT_SYMBOL_NS(intel_pcm_close, SND_SOC_SOF_INTEL_HIFI_EP_IPC);
99 MODULE_LICENSE("Dual BSD/GPL");