1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * skl-message.c - HDA DSP interface for FW registration, Pipe and Module
4*4882a593Smuzhiyun * configurations
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 2015 Intel Corp
7*4882a593Smuzhiyun * Author:Rafal Redzimski <rafal.f.redzimski@intel.com>
8*4882a593Smuzhiyun * Jeeja KP <jeeja.kp@intel.com>
9*4882a593Smuzhiyun * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10*4882a593Smuzhiyun */
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun #include <linux/slab.h>
13*4882a593Smuzhiyun #include <linux/pci.h>
14*4882a593Smuzhiyun #include <sound/core.h>
15*4882a593Smuzhiyun #include <sound/pcm.h>
16*4882a593Smuzhiyun #include <uapi/sound/skl-tplg-interface.h>
17*4882a593Smuzhiyun #include "skl-sst-dsp.h"
18*4882a593Smuzhiyun #include "cnl-sst-dsp.h"
19*4882a593Smuzhiyun #include "skl-sst-ipc.h"
20*4882a593Smuzhiyun #include "skl.h"
21*4882a593Smuzhiyun #include "../common/sst-dsp.h"
22*4882a593Smuzhiyun #include "../common/sst-dsp-priv.h"
23*4882a593Smuzhiyun #include "skl-topology.h"
24*4882a593Smuzhiyun
skl_alloc_dma_buf(struct device * dev,struct snd_dma_buffer * dmab,size_t size)25*4882a593Smuzhiyun static int skl_alloc_dma_buf(struct device *dev,
26*4882a593Smuzhiyun struct snd_dma_buffer *dmab, size_t size)
27*4882a593Smuzhiyun {
28*4882a593Smuzhiyun return snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dev, size, dmab);
29*4882a593Smuzhiyun }
30*4882a593Smuzhiyun
skl_free_dma_buf(struct device * dev,struct snd_dma_buffer * dmab)31*4882a593Smuzhiyun static int skl_free_dma_buf(struct device *dev, struct snd_dma_buffer *dmab)
32*4882a593Smuzhiyun {
33*4882a593Smuzhiyun snd_dma_free_pages(dmab);
34*4882a593Smuzhiyun return 0;
35*4882a593Smuzhiyun }
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun #define SKL_ASTATE_PARAM_ID 4
38*4882a593Smuzhiyun
skl_dsp_set_astate_cfg(struct skl_dev * skl,u32 cnt,void * data)39*4882a593Smuzhiyun void skl_dsp_set_astate_cfg(struct skl_dev *skl, u32 cnt, void *data)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun struct skl_ipc_large_config_msg msg = {0};
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun msg.large_param_id = SKL_ASTATE_PARAM_ID;
44*4882a593Smuzhiyun msg.param_data_size = (cnt * sizeof(struct skl_astate_param) +
45*4882a593Smuzhiyun sizeof(cnt));
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun skl_ipc_set_large_config(&skl->ipc, &msg, data);
48*4882a593Smuzhiyun }
49*4882a593Smuzhiyun
skl_dsp_setup_spib(struct device * dev,unsigned int size,int stream_tag,int enable)50*4882a593Smuzhiyun static int skl_dsp_setup_spib(struct device *dev, unsigned int size,
51*4882a593Smuzhiyun int stream_tag, int enable)
52*4882a593Smuzhiyun {
53*4882a593Smuzhiyun struct hdac_bus *bus = dev_get_drvdata(dev);
54*4882a593Smuzhiyun struct hdac_stream *stream = snd_hdac_get_stream(bus,
55*4882a593Smuzhiyun SNDRV_PCM_STREAM_PLAYBACK, stream_tag);
56*4882a593Smuzhiyun struct hdac_ext_stream *estream;
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun if (!stream)
59*4882a593Smuzhiyun return -EINVAL;
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun estream = stream_to_hdac_ext_stream(stream);
62*4882a593Smuzhiyun /* enable/disable SPIB for this hdac stream */
63*4882a593Smuzhiyun snd_hdac_ext_stream_spbcap_enable(bus, enable, stream->index);
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun /* set the spib value */
66*4882a593Smuzhiyun snd_hdac_ext_stream_set_spib(bus, estream, size);
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun return 0;
69*4882a593Smuzhiyun }
70*4882a593Smuzhiyun
skl_dsp_prepare(struct device * dev,unsigned int format,unsigned int size,struct snd_dma_buffer * dmab)71*4882a593Smuzhiyun static int skl_dsp_prepare(struct device *dev, unsigned int format,
72*4882a593Smuzhiyun unsigned int size, struct snd_dma_buffer *dmab)
73*4882a593Smuzhiyun {
74*4882a593Smuzhiyun struct hdac_bus *bus = dev_get_drvdata(dev);
75*4882a593Smuzhiyun struct hdac_ext_stream *estream;
76*4882a593Smuzhiyun struct hdac_stream *stream;
77*4882a593Smuzhiyun struct snd_pcm_substream substream;
78*4882a593Smuzhiyun int ret;
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun if (!bus)
81*4882a593Smuzhiyun return -ENODEV;
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun memset(&substream, 0, sizeof(substream));
84*4882a593Smuzhiyun substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun estream = snd_hdac_ext_stream_assign(bus, &substream,
87*4882a593Smuzhiyun HDAC_EXT_STREAM_TYPE_HOST);
88*4882a593Smuzhiyun if (!estream)
89*4882a593Smuzhiyun return -ENODEV;
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun stream = hdac_stream(estream);
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun /* assign decouple host dma channel */
94*4882a593Smuzhiyun ret = snd_hdac_dsp_prepare(stream, format, size, dmab);
95*4882a593Smuzhiyun if (ret < 0)
96*4882a593Smuzhiyun return ret;
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun skl_dsp_setup_spib(dev, size, stream->stream_tag, true);
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun return stream->stream_tag;
101*4882a593Smuzhiyun }
102*4882a593Smuzhiyun
skl_dsp_trigger(struct device * dev,bool start,int stream_tag)103*4882a593Smuzhiyun static int skl_dsp_trigger(struct device *dev, bool start, int stream_tag)
104*4882a593Smuzhiyun {
105*4882a593Smuzhiyun struct hdac_bus *bus = dev_get_drvdata(dev);
106*4882a593Smuzhiyun struct hdac_stream *stream;
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun if (!bus)
109*4882a593Smuzhiyun return -ENODEV;
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun stream = snd_hdac_get_stream(bus,
112*4882a593Smuzhiyun SNDRV_PCM_STREAM_PLAYBACK, stream_tag);
113*4882a593Smuzhiyun if (!stream)
114*4882a593Smuzhiyun return -EINVAL;
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun snd_hdac_dsp_trigger(stream, start);
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun return 0;
119*4882a593Smuzhiyun }
120*4882a593Smuzhiyun
skl_dsp_cleanup(struct device * dev,struct snd_dma_buffer * dmab,int stream_tag)121*4882a593Smuzhiyun static int skl_dsp_cleanup(struct device *dev,
122*4882a593Smuzhiyun struct snd_dma_buffer *dmab, int stream_tag)
123*4882a593Smuzhiyun {
124*4882a593Smuzhiyun struct hdac_bus *bus = dev_get_drvdata(dev);
125*4882a593Smuzhiyun struct hdac_stream *stream;
126*4882a593Smuzhiyun struct hdac_ext_stream *estream;
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun if (!bus)
129*4882a593Smuzhiyun return -ENODEV;
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun stream = snd_hdac_get_stream(bus,
132*4882a593Smuzhiyun SNDRV_PCM_STREAM_PLAYBACK, stream_tag);
133*4882a593Smuzhiyun if (!stream)
134*4882a593Smuzhiyun return -EINVAL;
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun estream = stream_to_hdac_ext_stream(stream);
137*4882a593Smuzhiyun skl_dsp_setup_spib(dev, 0, stream_tag, false);
138*4882a593Smuzhiyun snd_hdac_ext_stream_release(estream, HDAC_EXT_STREAM_TYPE_HOST);
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun snd_hdac_dsp_cleanup(stream, dmab);
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun return 0;
143*4882a593Smuzhiyun }
144*4882a593Smuzhiyun
skl_get_loader_ops(void)145*4882a593Smuzhiyun static struct skl_dsp_loader_ops skl_get_loader_ops(void)
146*4882a593Smuzhiyun {
147*4882a593Smuzhiyun struct skl_dsp_loader_ops loader_ops;
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun memset(&loader_ops, 0, sizeof(struct skl_dsp_loader_ops));
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun loader_ops.alloc_dma_buf = skl_alloc_dma_buf;
152*4882a593Smuzhiyun loader_ops.free_dma_buf = skl_free_dma_buf;
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun return loader_ops;
155*4882a593Smuzhiyun };
156*4882a593Smuzhiyun
bxt_get_loader_ops(void)157*4882a593Smuzhiyun static struct skl_dsp_loader_ops bxt_get_loader_ops(void)
158*4882a593Smuzhiyun {
159*4882a593Smuzhiyun struct skl_dsp_loader_ops loader_ops;
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun memset(&loader_ops, 0, sizeof(loader_ops));
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun loader_ops.alloc_dma_buf = skl_alloc_dma_buf;
164*4882a593Smuzhiyun loader_ops.free_dma_buf = skl_free_dma_buf;
165*4882a593Smuzhiyun loader_ops.prepare = skl_dsp_prepare;
166*4882a593Smuzhiyun loader_ops.trigger = skl_dsp_trigger;
167*4882a593Smuzhiyun loader_ops.cleanup = skl_dsp_cleanup;
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun return loader_ops;
170*4882a593Smuzhiyun };
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun static const struct skl_dsp_ops dsp_ops[] = {
173*4882a593Smuzhiyun {
174*4882a593Smuzhiyun .id = 0x9d70,
175*4882a593Smuzhiyun .num_cores = 2,
176*4882a593Smuzhiyun .loader_ops = skl_get_loader_ops,
177*4882a593Smuzhiyun .init = skl_sst_dsp_init,
178*4882a593Smuzhiyun .init_fw = skl_sst_init_fw,
179*4882a593Smuzhiyun .cleanup = skl_sst_dsp_cleanup
180*4882a593Smuzhiyun },
181*4882a593Smuzhiyun {
182*4882a593Smuzhiyun .id = 0x9d71,
183*4882a593Smuzhiyun .num_cores = 2,
184*4882a593Smuzhiyun .loader_ops = skl_get_loader_ops,
185*4882a593Smuzhiyun .init = skl_sst_dsp_init,
186*4882a593Smuzhiyun .init_fw = skl_sst_init_fw,
187*4882a593Smuzhiyun .cleanup = skl_sst_dsp_cleanup
188*4882a593Smuzhiyun },
189*4882a593Smuzhiyun {
190*4882a593Smuzhiyun .id = 0x5a98,
191*4882a593Smuzhiyun .num_cores = 2,
192*4882a593Smuzhiyun .loader_ops = bxt_get_loader_ops,
193*4882a593Smuzhiyun .init = bxt_sst_dsp_init,
194*4882a593Smuzhiyun .init_fw = bxt_sst_init_fw,
195*4882a593Smuzhiyun .cleanup = bxt_sst_dsp_cleanup
196*4882a593Smuzhiyun },
197*4882a593Smuzhiyun {
198*4882a593Smuzhiyun .id = 0x3198,
199*4882a593Smuzhiyun .num_cores = 2,
200*4882a593Smuzhiyun .loader_ops = bxt_get_loader_ops,
201*4882a593Smuzhiyun .init = bxt_sst_dsp_init,
202*4882a593Smuzhiyun .init_fw = bxt_sst_init_fw,
203*4882a593Smuzhiyun .cleanup = bxt_sst_dsp_cleanup
204*4882a593Smuzhiyun },
205*4882a593Smuzhiyun {
206*4882a593Smuzhiyun .id = 0x9dc8,
207*4882a593Smuzhiyun .num_cores = 4,
208*4882a593Smuzhiyun .loader_ops = bxt_get_loader_ops,
209*4882a593Smuzhiyun .init = cnl_sst_dsp_init,
210*4882a593Smuzhiyun .init_fw = cnl_sst_init_fw,
211*4882a593Smuzhiyun .cleanup = cnl_sst_dsp_cleanup
212*4882a593Smuzhiyun },
213*4882a593Smuzhiyun {
214*4882a593Smuzhiyun .id = 0xa348,
215*4882a593Smuzhiyun .num_cores = 4,
216*4882a593Smuzhiyun .loader_ops = bxt_get_loader_ops,
217*4882a593Smuzhiyun .init = cnl_sst_dsp_init,
218*4882a593Smuzhiyun .init_fw = cnl_sst_init_fw,
219*4882a593Smuzhiyun .cleanup = cnl_sst_dsp_cleanup
220*4882a593Smuzhiyun },
221*4882a593Smuzhiyun {
222*4882a593Smuzhiyun .id = 0x02c8,
223*4882a593Smuzhiyun .num_cores = 4,
224*4882a593Smuzhiyun .loader_ops = bxt_get_loader_ops,
225*4882a593Smuzhiyun .init = cnl_sst_dsp_init,
226*4882a593Smuzhiyun .init_fw = cnl_sst_init_fw,
227*4882a593Smuzhiyun .cleanup = cnl_sst_dsp_cleanup
228*4882a593Smuzhiyun },
229*4882a593Smuzhiyun {
230*4882a593Smuzhiyun .id = 0x06c8,
231*4882a593Smuzhiyun .num_cores = 4,
232*4882a593Smuzhiyun .loader_ops = bxt_get_loader_ops,
233*4882a593Smuzhiyun .init = cnl_sst_dsp_init,
234*4882a593Smuzhiyun .init_fw = cnl_sst_init_fw,
235*4882a593Smuzhiyun .cleanup = cnl_sst_dsp_cleanup
236*4882a593Smuzhiyun },
237*4882a593Smuzhiyun };
238*4882a593Smuzhiyun
skl_get_dsp_ops(int pci_id)239*4882a593Smuzhiyun const struct skl_dsp_ops *skl_get_dsp_ops(int pci_id)
240*4882a593Smuzhiyun {
241*4882a593Smuzhiyun int i;
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(dsp_ops); i++) {
244*4882a593Smuzhiyun if (dsp_ops[i].id == pci_id)
245*4882a593Smuzhiyun return &dsp_ops[i];
246*4882a593Smuzhiyun }
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun return NULL;
249*4882a593Smuzhiyun }
250*4882a593Smuzhiyun
skl_init_dsp(struct skl_dev * skl)251*4882a593Smuzhiyun int skl_init_dsp(struct skl_dev *skl)
252*4882a593Smuzhiyun {
253*4882a593Smuzhiyun void __iomem *mmio_base;
254*4882a593Smuzhiyun struct hdac_bus *bus = skl_to_bus(skl);
255*4882a593Smuzhiyun struct skl_dsp_loader_ops loader_ops;
256*4882a593Smuzhiyun int irq = bus->irq;
257*4882a593Smuzhiyun const struct skl_dsp_ops *ops;
258*4882a593Smuzhiyun struct skl_dsp_cores *cores;
259*4882a593Smuzhiyun int ret;
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun /* enable ppcap interrupt */
262*4882a593Smuzhiyun snd_hdac_ext_bus_ppcap_enable(bus, true);
263*4882a593Smuzhiyun snd_hdac_ext_bus_ppcap_int_enable(bus, true);
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun /* read the BAR of the ADSP MMIO */
266*4882a593Smuzhiyun mmio_base = pci_ioremap_bar(skl->pci, 4);
267*4882a593Smuzhiyun if (mmio_base == NULL) {
268*4882a593Smuzhiyun dev_err(bus->dev, "ioremap error\n");
269*4882a593Smuzhiyun return -ENXIO;
270*4882a593Smuzhiyun }
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun ops = skl_get_dsp_ops(skl->pci->device);
273*4882a593Smuzhiyun if (!ops) {
274*4882a593Smuzhiyun ret = -EIO;
275*4882a593Smuzhiyun goto unmap_mmio;
276*4882a593Smuzhiyun }
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun loader_ops = ops->loader_ops();
279*4882a593Smuzhiyun ret = ops->init(bus->dev, mmio_base, irq,
280*4882a593Smuzhiyun skl->fw_name, loader_ops,
281*4882a593Smuzhiyun &skl);
282*4882a593Smuzhiyun
283*4882a593Smuzhiyun if (ret < 0)
284*4882a593Smuzhiyun goto unmap_mmio;
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun skl->dsp_ops = ops;
287*4882a593Smuzhiyun cores = &skl->cores;
288*4882a593Smuzhiyun cores->count = ops->num_cores;
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun cores->state = kcalloc(cores->count, sizeof(*cores->state), GFP_KERNEL);
291*4882a593Smuzhiyun if (!cores->state) {
292*4882a593Smuzhiyun ret = -ENOMEM;
293*4882a593Smuzhiyun goto unmap_mmio;
294*4882a593Smuzhiyun }
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun cores->usage_count = kcalloc(cores->count, sizeof(*cores->usage_count),
297*4882a593Smuzhiyun GFP_KERNEL);
298*4882a593Smuzhiyun if (!cores->usage_count) {
299*4882a593Smuzhiyun ret = -ENOMEM;
300*4882a593Smuzhiyun goto free_core_state;
301*4882a593Smuzhiyun }
302*4882a593Smuzhiyun
303*4882a593Smuzhiyun dev_dbg(bus->dev, "dsp registration status=%d\n", ret);
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun return 0;
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun free_core_state:
308*4882a593Smuzhiyun kfree(cores->state);
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun unmap_mmio:
311*4882a593Smuzhiyun iounmap(mmio_base);
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun return ret;
314*4882a593Smuzhiyun }
315*4882a593Smuzhiyun
skl_free_dsp(struct skl_dev * skl)316*4882a593Smuzhiyun int skl_free_dsp(struct skl_dev *skl)
317*4882a593Smuzhiyun {
318*4882a593Smuzhiyun struct hdac_bus *bus = skl_to_bus(skl);
319*4882a593Smuzhiyun
320*4882a593Smuzhiyun /* disable ppcap interrupt */
321*4882a593Smuzhiyun snd_hdac_ext_bus_ppcap_int_enable(bus, false);
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun skl->dsp_ops->cleanup(bus->dev, skl);
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun kfree(skl->cores.state);
326*4882a593Smuzhiyun kfree(skl->cores.usage_count);
327*4882a593Smuzhiyun
328*4882a593Smuzhiyun if (skl->dsp->addr.lpe)
329*4882a593Smuzhiyun iounmap(skl->dsp->addr.lpe);
330*4882a593Smuzhiyun
331*4882a593Smuzhiyun return 0;
332*4882a593Smuzhiyun }
333*4882a593Smuzhiyun
334*4882a593Smuzhiyun /*
335*4882a593Smuzhiyun * In the case of "suspend_active" i.e, the Audio IP being active
336*4882a593Smuzhiyun * during system suspend, immediately excecute any pending D0i3 work
337*4882a593Smuzhiyun * before suspending. This is needed for the IP to work in low power
338*4882a593Smuzhiyun * mode during system suspend. In the case of normal suspend, cancel
339*4882a593Smuzhiyun * any pending D0i3 work.
340*4882a593Smuzhiyun */
skl_suspend_late_dsp(struct skl_dev * skl)341*4882a593Smuzhiyun int skl_suspend_late_dsp(struct skl_dev *skl)
342*4882a593Smuzhiyun {
343*4882a593Smuzhiyun struct delayed_work *dwork;
344*4882a593Smuzhiyun
345*4882a593Smuzhiyun if (!skl)
346*4882a593Smuzhiyun return 0;
347*4882a593Smuzhiyun
348*4882a593Smuzhiyun dwork = &skl->d0i3.work;
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun if (dwork->work.func) {
351*4882a593Smuzhiyun if (skl->supend_active)
352*4882a593Smuzhiyun flush_delayed_work(dwork);
353*4882a593Smuzhiyun else
354*4882a593Smuzhiyun cancel_delayed_work_sync(dwork);
355*4882a593Smuzhiyun }
356*4882a593Smuzhiyun
357*4882a593Smuzhiyun return 0;
358*4882a593Smuzhiyun }
359*4882a593Smuzhiyun
skl_suspend_dsp(struct skl_dev * skl)360*4882a593Smuzhiyun int skl_suspend_dsp(struct skl_dev *skl)
361*4882a593Smuzhiyun {
362*4882a593Smuzhiyun struct hdac_bus *bus = skl_to_bus(skl);
363*4882a593Smuzhiyun int ret;
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun /* if ppcap is not supported return 0 */
366*4882a593Smuzhiyun if (!bus->ppcap)
367*4882a593Smuzhiyun return 0;
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun ret = skl_dsp_sleep(skl->dsp);
370*4882a593Smuzhiyun if (ret < 0)
371*4882a593Smuzhiyun return ret;
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun /* disable ppcap interrupt */
374*4882a593Smuzhiyun snd_hdac_ext_bus_ppcap_int_enable(bus, false);
375*4882a593Smuzhiyun snd_hdac_ext_bus_ppcap_enable(bus, false);
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun return 0;
378*4882a593Smuzhiyun }
379*4882a593Smuzhiyun
skl_resume_dsp(struct skl_dev * skl)380*4882a593Smuzhiyun int skl_resume_dsp(struct skl_dev *skl)
381*4882a593Smuzhiyun {
382*4882a593Smuzhiyun struct hdac_bus *bus = skl_to_bus(skl);
383*4882a593Smuzhiyun int ret;
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun /* if ppcap is not supported return 0 */
386*4882a593Smuzhiyun if (!bus->ppcap)
387*4882a593Smuzhiyun return 0;
388*4882a593Smuzhiyun
389*4882a593Smuzhiyun /* enable ppcap interrupt */
390*4882a593Smuzhiyun snd_hdac_ext_bus_ppcap_enable(bus, true);
391*4882a593Smuzhiyun snd_hdac_ext_bus_ppcap_int_enable(bus, true);
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun /* check if DSP 1st boot is done */
394*4882a593Smuzhiyun if (skl->is_first_boot)
395*4882a593Smuzhiyun return 0;
396*4882a593Smuzhiyun
397*4882a593Smuzhiyun /*
398*4882a593Smuzhiyun * Disable dynamic clock and power gating during firmware
399*4882a593Smuzhiyun * and library download
400*4882a593Smuzhiyun */
401*4882a593Smuzhiyun skl->enable_miscbdcge(skl->dev, false);
402*4882a593Smuzhiyun skl->clock_power_gating(skl->dev, false);
403*4882a593Smuzhiyun
404*4882a593Smuzhiyun ret = skl_dsp_wake(skl->dsp);
405*4882a593Smuzhiyun skl->enable_miscbdcge(skl->dev, true);
406*4882a593Smuzhiyun skl->clock_power_gating(skl->dev, true);
407*4882a593Smuzhiyun if (ret < 0)
408*4882a593Smuzhiyun return ret;
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun if (skl->cfg.astate_cfg != NULL) {
411*4882a593Smuzhiyun skl_dsp_set_astate_cfg(skl, skl->cfg.astate_cfg->count,
412*4882a593Smuzhiyun skl->cfg.astate_cfg);
413*4882a593Smuzhiyun }
414*4882a593Smuzhiyun return ret;
415*4882a593Smuzhiyun }
416*4882a593Smuzhiyun
skl_get_bit_depth(int params)417*4882a593Smuzhiyun enum skl_bitdepth skl_get_bit_depth(int params)
418*4882a593Smuzhiyun {
419*4882a593Smuzhiyun switch (params) {
420*4882a593Smuzhiyun case 8:
421*4882a593Smuzhiyun return SKL_DEPTH_8BIT;
422*4882a593Smuzhiyun
423*4882a593Smuzhiyun case 16:
424*4882a593Smuzhiyun return SKL_DEPTH_16BIT;
425*4882a593Smuzhiyun
426*4882a593Smuzhiyun case 24:
427*4882a593Smuzhiyun return SKL_DEPTH_24BIT;
428*4882a593Smuzhiyun
429*4882a593Smuzhiyun case 32:
430*4882a593Smuzhiyun return SKL_DEPTH_32BIT;
431*4882a593Smuzhiyun
432*4882a593Smuzhiyun default:
433*4882a593Smuzhiyun return SKL_DEPTH_INVALID;
434*4882a593Smuzhiyun
435*4882a593Smuzhiyun }
436*4882a593Smuzhiyun }
437*4882a593Smuzhiyun
438*4882a593Smuzhiyun /*
439*4882a593Smuzhiyun * Each module in DSP expects a base module configuration, which consists of
440*4882a593Smuzhiyun * PCM format information, which we calculate in driver and resource values
441*4882a593Smuzhiyun * which are read from widget information passed through topology binary
442*4882a593Smuzhiyun * This is send when we create a module with INIT_INSTANCE IPC msg
443*4882a593Smuzhiyun */
skl_set_base_module_format(struct skl_dev * skl,struct skl_module_cfg * mconfig,struct skl_base_cfg * base_cfg)444*4882a593Smuzhiyun static void skl_set_base_module_format(struct skl_dev *skl,
445*4882a593Smuzhiyun struct skl_module_cfg *mconfig,
446*4882a593Smuzhiyun struct skl_base_cfg *base_cfg)
447*4882a593Smuzhiyun {
448*4882a593Smuzhiyun struct skl_module *module = mconfig->module;
449*4882a593Smuzhiyun struct skl_module_res *res = &module->resources[mconfig->res_idx];
450*4882a593Smuzhiyun struct skl_module_iface *fmt = &module->formats[mconfig->fmt_idx];
451*4882a593Smuzhiyun struct skl_module_fmt *format = &fmt->inputs[0].fmt;
452*4882a593Smuzhiyun
453*4882a593Smuzhiyun base_cfg->audio_fmt.number_of_channels = format->channels;
454*4882a593Smuzhiyun
455*4882a593Smuzhiyun base_cfg->audio_fmt.s_freq = format->s_freq;
456*4882a593Smuzhiyun base_cfg->audio_fmt.bit_depth = format->bit_depth;
457*4882a593Smuzhiyun base_cfg->audio_fmt.valid_bit_depth = format->valid_bit_depth;
458*4882a593Smuzhiyun base_cfg->audio_fmt.ch_cfg = format->ch_cfg;
459*4882a593Smuzhiyun base_cfg->audio_fmt.sample_type = format->sample_type;
460*4882a593Smuzhiyun
461*4882a593Smuzhiyun dev_dbg(skl->dev, "bit_depth=%x valid_bd=%x ch_config=%x\n",
462*4882a593Smuzhiyun format->bit_depth, format->valid_bit_depth,
463*4882a593Smuzhiyun format->ch_cfg);
464*4882a593Smuzhiyun
465*4882a593Smuzhiyun base_cfg->audio_fmt.channel_map = format->ch_map;
466*4882a593Smuzhiyun
467*4882a593Smuzhiyun base_cfg->audio_fmt.interleaving = format->interleaving_style;
468*4882a593Smuzhiyun
469*4882a593Smuzhiyun base_cfg->cpc = res->cpc;
470*4882a593Smuzhiyun base_cfg->ibs = res->ibs;
471*4882a593Smuzhiyun base_cfg->obs = res->obs;
472*4882a593Smuzhiyun base_cfg->is_pages = res->is_pages;
473*4882a593Smuzhiyun }
474*4882a593Smuzhiyun
475*4882a593Smuzhiyun /*
476*4882a593Smuzhiyun * Copies copier capabilities into copier module and updates copier module
477*4882a593Smuzhiyun * config size.
478*4882a593Smuzhiyun */
skl_copy_copier_caps(struct skl_module_cfg * mconfig,struct skl_cpr_cfg * cpr_mconfig)479*4882a593Smuzhiyun static void skl_copy_copier_caps(struct skl_module_cfg *mconfig,
480*4882a593Smuzhiyun struct skl_cpr_cfg *cpr_mconfig)
481*4882a593Smuzhiyun {
482*4882a593Smuzhiyun if (mconfig->formats_config.caps_size == 0)
483*4882a593Smuzhiyun return;
484*4882a593Smuzhiyun
485*4882a593Smuzhiyun memcpy(cpr_mconfig->gtw_cfg.config_data,
486*4882a593Smuzhiyun mconfig->formats_config.caps,
487*4882a593Smuzhiyun mconfig->formats_config.caps_size);
488*4882a593Smuzhiyun
489*4882a593Smuzhiyun cpr_mconfig->gtw_cfg.config_length =
490*4882a593Smuzhiyun (mconfig->formats_config.caps_size) / 4;
491*4882a593Smuzhiyun }
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun #define SKL_NON_GATEWAY_CPR_NODE_ID 0xFFFFFFFF
494*4882a593Smuzhiyun /*
495*4882a593Smuzhiyun * Calculate the gatewat settings required for copier module, type of
496*4882a593Smuzhiyun * gateway and index of gateway to use
497*4882a593Smuzhiyun */
skl_get_node_id(struct skl_dev * skl,struct skl_module_cfg * mconfig)498*4882a593Smuzhiyun static u32 skl_get_node_id(struct skl_dev *skl,
499*4882a593Smuzhiyun struct skl_module_cfg *mconfig)
500*4882a593Smuzhiyun {
501*4882a593Smuzhiyun union skl_connector_node_id node_id = {0};
502*4882a593Smuzhiyun union skl_ssp_dma_node ssp_node = {0};
503*4882a593Smuzhiyun struct skl_pipe_params *params = mconfig->pipe->p_params;
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun switch (mconfig->dev_type) {
506*4882a593Smuzhiyun case SKL_DEVICE_BT:
507*4882a593Smuzhiyun node_id.node.dma_type =
508*4882a593Smuzhiyun (SKL_CONN_SOURCE == mconfig->hw_conn_type) ?
509*4882a593Smuzhiyun SKL_DMA_I2S_LINK_OUTPUT_CLASS :
510*4882a593Smuzhiyun SKL_DMA_I2S_LINK_INPUT_CLASS;
511*4882a593Smuzhiyun node_id.node.vindex = params->host_dma_id +
512*4882a593Smuzhiyun (mconfig->vbus_id << 3);
513*4882a593Smuzhiyun break;
514*4882a593Smuzhiyun
515*4882a593Smuzhiyun case SKL_DEVICE_I2S:
516*4882a593Smuzhiyun node_id.node.dma_type =
517*4882a593Smuzhiyun (SKL_CONN_SOURCE == mconfig->hw_conn_type) ?
518*4882a593Smuzhiyun SKL_DMA_I2S_LINK_OUTPUT_CLASS :
519*4882a593Smuzhiyun SKL_DMA_I2S_LINK_INPUT_CLASS;
520*4882a593Smuzhiyun ssp_node.dma_node.time_slot_index = mconfig->time_slot;
521*4882a593Smuzhiyun ssp_node.dma_node.i2s_instance = mconfig->vbus_id;
522*4882a593Smuzhiyun node_id.node.vindex = ssp_node.val;
523*4882a593Smuzhiyun break;
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun case SKL_DEVICE_DMIC:
526*4882a593Smuzhiyun node_id.node.dma_type = SKL_DMA_DMIC_LINK_INPUT_CLASS;
527*4882a593Smuzhiyun node_id.node.vindex = mconfig->vbus_id +
528*4882a593Smuzhiyun (mconfig->time_slot);
529*4882a593Smuzhiyun break;
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun case SKL_DEVICE_HDALINK:
532*4882a593Smuzhiyun node_id.node.dma_type =
533*4882a593Smuzhiyun (SKL_CONN_SOURCE == mconfig->hw_conn_type) ?
534*4882a593Smuzhiyun SKL_DMA_HDA_LINK_OUTPUT_CLASS :
535*4882a593Smuzhiyun SKL_DMA_HDA_LINK_INPUT_CLASS;
536*4882a593Smuzhiyun node_id.node.vindex = params->link_dma_id;
537*4882a593Smuzhiyun break;
538*4882a593Smuzhiyun
539*4882a593Smuzhiyun case SKL_DEVICE_HDAHOST:
540*4882a593Smuzhiyun node_id.node.dma_type =
541*4882a593Smuzhiyun (SKL_CONN_SOURCE == mconfig->hw_conn_type) ?
542*4882a593Smuzhiyun SKL_DMA_HDA_HOST_OUTPUT_CLASS :
543*4882a593Smuzhiyun SKL_DMA_HDA_HOST_INPUT_CLASS;
544*4882a593Smuzhiyun node_id.node.vindex = params->host_dma_id;
545*4882a593Smuzhiyun break;
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun default:
548*4882a593Smuzhiyun node_id.val = 0xFFFFFFFF;
549*4882a593Smuzhiyun break;
550*4882a593Smuzhiyun }
551*4882a593Smuzhiyun
552*4882a593Smuzhiyun return node_id.val;
553*4882a593Smuzhiyun }
554*4882a593Smuzhiyun
skl_setup_cpr_gateway_cfg(struct skl_dev * skl,struct skl_module_cfg * mconfig,struct skl_cpr_cfg * cpr_mconfig)555*4882a593Smuzhiyun static void skl_setup_cpr_gateway_cfg(struct skl_dev *skl,
556*4882a593Smuzhiyun struct skl_module_cfg *mconfig,
557*4882a593Smuzhiyun struct skl_cpr_cfg *cpr_mconfig)
558*4882a593Smuzhiyun {
559*4882a593Smuzhiyun u32 dma_io_buf;
560*4882a593Smuzhiyun struct skl_module_res *res;
561*4882a593Smuzhiyun int res_idx = mconfig->res_idx;
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun cpr_mconfig->gtw_cfg.node_id = skl_get_node_id(skl, mconfig);
564*4882a593Smuzhiyun
565*4882a593Smuzhiyun if (cpr_mconfig->gtw_cfg.node_id == SKL_NON_GATEWAY_CPR_NODE_ID) {
566*4882a593Smuzhiyun cpr_mconfig->cpr_feature_mask = 0;
567*4882a593Smuzhiyun return;
568*4882a593Smuzhiyun }
569*4882a593Smuzhiyun
570*4882a593Smuzhiyun if (skl->nr_modules) {
571*4882a593Smuzhiyun res = &mconfig->module->resources[mconfig->res_idx];
572*4882a593Smuzhiyun cpr_mconfig->gtw_cfg.dma_buffer_size = res->dma_buffer_size;
573*4882a593Smuzhiyun goto skip_buf_size_calc;
574*4882a593Smuzhiyun } else {
575*4882a593Smuzhiyun res = &mconfig->module->resources[res_idx];
576*4882a593Smuzhiyun }
577*4882a593Smuzhiyun
578*4882a593Smuzhiyun switch (mconfig->hw_conn_type) {
579*4882a593Smuzhiyun case SKL_CONN_SOURCE:
580*4882a593Smuzhiyun if (mconfig->dev_type == SKL_DEVICE_HDAHOST)
581*4882a593Smuzhiyun dma_io_buf = res->ibs;
582*4882a593Smuzhiyun else
583*4882a593Smuzhiyun dma_io_buf = res->obs;
584*4882a593Smuzhiyun break;
585*4882a593Smuzhiyun
586*4882a593Smuzhiyun case SKL_CONN_SINK:
587*4882a593Smuzhiyun if (mconfig->dev_type == SKL_DEVICE_HDAHOST)
588*4882a593Smuzhiyun dma_io_buf = res->obs;
589*4882a593Smuzhiyun else
590*4882a593Smuzhiyun dma_io_buf = res->ibs;
591*4882a593Smuzhiyun break;
592*4882a593Smuzhiyun
593*4882a593Smuzhiyun default:
594*4882a593Smuzhiyun dev_warn(skl->dev, "wrong connection type: %d\n",
595*4882a593Smuzhiyun mconfig->hw_conn_type);
596*4882a593Smuzhiyun return;
597*4882a593Smuzhiyun }
598*4882a593Smuzhiyun
599*4882a593Smuzhiyun cpr_mconfig->gtw_cfg.dma_buffer_size =
600*4882a593Smuzhiyun mconfig->dma_buffer_size * dma_io_buf;
601*4882a593Smuzhiyun
602*4882a593Smuzhiyun /* fallback to 2ms default value */
603*4882a593Smuzhiyun if (!cpr_mconfig->gtw_cfg.dma_buffer_size) {
604*4882a593Smuzhiyun if (mconfig->hw_conn_type == SKL_CONN_SOURCE)
605*4882a593Smuzhiyun cpr_mconfig->gtw_cfg.dma_buffer_size = 2 * res->obs;
606*4882a593Smuzhiyun else
607*4882a593Smuzhiyun cpr_mconfig->gtw_cfg.dma_buffer_size = 2 * res->ibs;
608*4882a593Smuzhiyun }
609*4882a593Smuzhiyun
610*4882a593Smuzhiyun skip_buf_size_calc:
611*4882a593Smuzhiyun cpr_mconfig->cpr_feature_mask = 0;
612*4882a593Smuzhiyun cpr_mconfig->gtw_cfg.config_length = 0;
613*4882a593Smuzhiyun
614*4882a593Smuzhiyun skl_copy_copier_caps(mconfig, cpr_mconfig);
615*4882a593Smuzhiyun }
616*4882a593Smuzhiyun
617*4882a593Smuzhiyun #define DMA_CONTROL_ID 5
618*4882a593Smuzhiyun #define DMA_I2S_BLOB_SIZE 21
619*4882a593Smuzhiyun
skl_dsp_set_dma_control(struct skl_dev * skl,u32 * caps,u32 caps_size,u32 node_id)620*4882a593Smuzhiyun int skl_dsp_set_dma_control(struct skl_dev *skl, u32 *caps,
621*4882a593Smuzhiyun u32 caps_size, u32 node_id)
622*4882a593Smuzhiyun {
623*4882a593Smuzhiyun struct skl_dma_control *dma_ctrl;
624*4882a593Smuzhiyun struct skl_ipc_large_config_msg msg = {0};
625*4882a593Smuzhiyun int err = 0;
626*4882a593Smuzhiyun
627*4882a593Smuzhiyun
628*4882a593Smuzhiyun /*
629*4882a593Smuzhiyun * if blob size zero, then return
630*4882a593Smuzhiyun */
631*4882a593Smuzhiyun if (caps_size == 0)
632*4882a593Smuzhiyun return 0;
633*4882a593Smuzhiyun
634*4882a593Smuzhiyun msg.large_param_id = DMA_CONTROL_ID;
635*4882a593Smuzhiyun msg.param_data_size = sizeof(struct skl_dma_control) + caps_size;
636*4882a593Smuzhiyun
637*4882a593Smuzhiyun dma_ctrl = kzalloc(msg.param_data_size, GFP_KERNEL);
638*4882a593Smuzhiyun if (dma_ctrl == NULL)
639*4882a593Smuzhiyun return -ENOMEM;
640*4882a593Smuzhiyun
641*4882a593Smuzhiyun dma_ctrl->node_id = node_id;
642*4882a593Smuzhiyun
643*4882a593Smuzhiyun /*
644*4882a593Smuzhiyun * NHLT blob may contain additional configs along with i2s blob.
645*4882a593Smuzhiyun * firmware expects only the i2s blob size as the config_length.
646*4882a593Smuzhiyun * So fix to i2s blob size.
647*4882a593Smuzhiyun * size in dwords.
648*4882a593Smuzhiyun */
649*4882a593Smuzhiyun dma_ctrl->config_length = DMA_I2S_BLOB_SIZE;
650*4882a593Smuzhiyun
651*4882a593Smuzhiyun memcpy(dma_ctrl->config_data, caps, caps_size);
652*4882a593Smuzhiyun
653*4882a593Smuzhiyun err = skl_ipc_set_large_config(&skl->ipc, &msg, (u32 *)dma_ctrl);
654*4882a593Smuzhiyun
655*4882a593Smuzhiyun kfree(dma_ctrl);
656*4882a593Smuzhiyun return err;
657*4882a593Smuzhiyun }
658*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(skl_dsp_set_dma_control);
659*4882a593Smuzhiyun
skl_setup_out_format(struct skl_dev * skl,struct skl_module_cfg * mconfig,struct skl_audio_data_format * out_fmt)660*4882a593Smuzhiyun static void skl_setup_out_format(struct skl_dev *skl,
661*4882a593Smuzhiyun struct skl_module_cfg *mconfig,
662*4882a593Smuzhiyun struct skl_audio_data_format *out_fmt)
663*4882a593Smuzhiyun {
664*4882a593Smuzhiyun struct skl_module *module = mconfig->module;
665*4882a593Smuzhiyun struct skl_module_iface *fmt = &module->formats[mconfig->fmt_idx];
666*4882a593Smuzhiyun struct skl_module_fmt *format = &fmt->outputs[0].fmt;
667*4882a593Smuzhiyun
668*4882a593Smuzhiyun out_fmt->number_of_channels = (u8)format->channels;
669*4882a593Smuzhiyun out_fmt->s_freq = format->s_freq;
670*4882a593Smuzhiyun out_fmt->bit_depth = format->bit_depth;
671*4882a593Smuzhiyun out_fmt->valid_bit_depth = format->valid_bit_depth;
672*4882a593Smuzhiyun out_fmt->ch_cfg = format->ch_cfg;
673*4882a593Smuzhiyun
674*4882a593Smuzhiyun out_fmt->channel_map = format->ch_map;
675*4882a593Smuzhiyun out_fmt->interleaving = format->interleaving_style;
676*4882a593Smuzhiyun out_fmt->sample_type = format->sample_type;
677*4882a593Smuzhiyun
678*4882a593Smuzhiyun dev_dbg(skl->dev, "copier out format chan=%d fre=%d bitdepth=%d\n",
679*4882a593Smuzhiyun out_fmt->number_of_channels, format->s_freq, format->bit_depth);
680*4882a593Smuzhiyun }
681*4882a593Smuzhiyun
682*4882a593Smuzhiyun /*
683*4882a593Smuzhiyun * DSP needs SRC module for frequency conversion, SRC takes base module
684*4882a593Smuzhiyun * configuration and the target frequency as extra parameter passed as src
685*4882a593Smuzhiyun * config
686*4882a593Smuzhiyun */
skl_set_src_format(struct skl_dev * skl,struct skl_module_cfg * mconfig,struct skl_src_module_cfg * src_mconfig)687*4882a593Smuzhiyun static void skl_set_src_format(struct skl_dev *skl,
688*4882a593Smuzhiyun struct skl_module_cfg *mconfig,
689*4882a593Smuzhiyun struct skl_src_module_cfg *src_mconfig)
690*4882a593Smuzhiyun {
691*4882a593Smuzhiyun struct skl_module *module = mconfig->module;
692*4882a593Smuzhiyun struct skl_module_iface *iface = &module->formats[mconfig->fmt_idx];
693*4882a593Smuzhiyun struct skl_module_fmt *fmt = &iface->outputs[0].fmt;
694*4882a593Smuzhiyun
695*4882a593Smuzhiyun skl_set_base_module_format(skl, mconfig,
696*4882a593Smuzhiyun (struct skl_base_cfg *)src_mconfig);
697*4882a593Smuzhiyun
698*4882a593Smuzhiyun src_mconfig->src_cfg = fmt->s_freq;
699*4882a593Smuzhiyun }
700*4882a593Smuzhiyun
701*4882a593Smuzhiyun /*
702*4882a593Smuzhiyun * DSP needs updown module to do channel conversion. updown module take base
703*4882a593Smuzhiyun * module configuration and channel configuration
704*4882a593Smuzhiyun * It also take coefficients and now we have defaults applied here
705*4882a593Smuzhiyun */
skl_set_updown_mixer_format(struct skl_dev * skl,struct skl_module_cfg * mconfig,struct skl_up_down_mixer_cfg * mixer_mconfig)706*4882a593Smuzhiyun static void skl_set_updown_mixer_format(struct skl_dev *skl,
707*4882a593Smuzhiyun struct skl_module_cfg *mconfig,
708*4882a593Smuzhiyun struct skl_up_down_mixer_cfg *mixer_mconfig)
709*4882a593Smuzhiyun {
710*4882a593Smuzhiyun struct skl_module *module = mconfig->module;
711*4882a593Smuzhiyun struct skl_module_iface *iface = &module->formats[mconfig->fmt_idx];
712*4882a593Smuzhiyun struct skl_module_fmt *fmt = &iface->outputs[0].fmt;
713*4882a593Smuzhiyun
714*4882a593Smuzhiyun skl_set_base_module_format(skl, mconfig,
715*4882a593Smuzhiyun (struct skl_base_cfg *)mixer_mconfig);
716*4882a593Smuzhiyun mixer_mconfig->out_ch_cfg = fmt->ch_cfg;
717*4882a593Smuzhiyun mixer_mconfig->ch_map = fmt->ch_map;
718*4882a593Smuzhiyun }
719*4882a593Smuzhiyun
720*4882a593Smuzhiyun /*
721*4882a593Smuzhiyun * 'copier' is DSP internal module which copies data from Host DMA (HDA host
722*4882a593Smuzhiyun * dma) or link (hda link, SSP, PDM)
723*4882a593Smuzhiyun * Here we calculate the copier module parameters, like PCM format, output
724*4882a593Smuzhiyun * format, gateway settings
725*4882a593Smuzhiyun * copier_module_config is sent as input buffer with INIT_INSTANCE IPC msg
726*4882a593Smuzhiyun */
skl_set_copier_format(struct skl_dev * skl,struct skl_module_cfg * mconfig,struct skl_cpr_cfg * cpr_mconfig)727*4882a593Smuzhiyun static void skl_set_copier_format(struct skl_dev *skl,
728*4882a593Smuzhiyun struct skl_module_cfg *mconfig,
729*4882a593Smuzhiyun struct skl_cpr_cfg *cpr_mconfig)
730*4882a593Smuzhiyun {
731*4882a593Smuzhiyun struct skl_audio_data_format *out_fmt = &cpr_mconfig->out_fmt;
732*4882a593Smuzhiyun struct skl_base_cfg *base_cfg = (struct skl_base_cfg *)cpr_mconfig;
733*4882a593Smuzhiyun
734*4882a593Smuzhiyun skl_set_base_module_format(skl, mconfig, base_cfg);
735*4882a593Smuzhiyun
736*4882a593Smuzhiyun skl_setup_out_format(skl, mconfig, out_fmt);
737*4882a593Smuzhiyun skl_setup_cpr_gateway_cfg(skl, mconfig, cpr_mconfig);
738*4882a593Smuzhiyun }
739*4882a593Smuzhiyun
740*4882a593Smuzhiyun /*
741*4882a593Smuzhiyun * Algo module are DSP pre processing modules. Algo module take base module
742*4882a593Smuzhiyun * configuration and params
743*4882a593Smuzhiyun */
744*4882a593Smuzhiyun
skl_set_algo_format(struct skl_dev * skl,struct skl_module_cfg * mconfig,struct skl_algo_cfg * algo_mcfg)745*4882a593Smuzhiyun static void skl_set_algo_format(struct skl_dev *skl,
746*4882a593Smuzhiyun struct skl_module_cfg *mconfig,
747*4882a593Smuzhiyun struct skl_algo_cfg *algo_mcfg)
748*4882a593Smuzhiyun {
749*4882a593Smuzhiyun struct skl_base_cfg *base_cfg = (struct skl_base_cfg *)algo_mcfg;
750*4882a593Smuzhiyun
751*4882a593Smuzhiyun skl_set_base_module_format(skl, mconfig, base_cfg);
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun if (mconfig->formats_config.caps_size == 0)
754*4882a593Smuzhiyun return;
755*4882a593Smuzhiyun
756*4882a593Smuzhiyun memcpy(algo_mcfg->params,
757*4882a593Smuzhiyun mconfig->formats_config.caps,
758*4882a593Smuzhiyun mconfig->formats_config.caps_size);
759*4882a593Smuzhiyun
760*4882a593Smuzhiyun }
761*4882a593Smuzhiyun
762*4882a593Smuzhiyun /*
763*4882a593Smuzhiyun * Mic select module allows selecting one or many input channels, thus
764*4882a593Smuzhiyun * acting as a demux.
765*4882a593Smuzhiyun *
766*4882a593Smuzhiyun * Mic select module take base module configuration and out-format
767*4882a593Smuzhiyun * configuration
768*4882a593Smuzhiyun */
skl_set_base_outfmt_format(struct skl_dev * skl,struct skl_module_cfg * mconfig,struct skl_base_outfmt_cfg * base_outfmt_mcfg)769*4882a593Smuzhiyun static void skl_set_base_outfmt_format(struct skl_dev *skl,
770*4882a593Smuzhiyun struct skl_module_cfg *mconfig,
771*4882a593Smuzhiyun struct skl_base_outfmt_cfg *base_outfmt_mcfg)
772*4882a593Smuzhiyun {
773*4882a593Smuzhiyun struct skl_audio_data_format *out_fmt = &base_outfmt_mcfg->out_fmt;
774*4882a593Smuzhiyun struct skl_base_cfg *base_cfg =
775*4882a593Smuzhiyun (struct skl_base_cfg *)base_outfmt_mcfg;
776*4882a593Smuzhiyun
777*4882a593Smuzhiyun skl_set_base_module_format(skl, mconfig, base_cfg);
778*4882a593Smuzhiyun skl_setup_out_format(skl, mconfig, out_fmt);
779*4882a593Smuzhiyun }
780*4882a593Smuzhiyun
skl_get_module_param_size(struct skl_dev * skl,struct skl_module_cfg * mconfig)781*4882a593Smuzhiyun static u16 skl_get_module_param_size(struct skl_dev *skl,
782*4882a593Smuzhiyun struct skl_module_cfg *mconfig)
783*4882a593Smuzhiyun {
784*4882a593Smuzhiyun u16 param_size;
785*4882a593Smuzhiyun
786*4882a593Smuzhiyun switch (mconfig->m_type) {
787*4882a593Smuzhiyun case SKL_MODULE_TYPE_COPIER:
788*4882a593Smuzhiyun param_size = sizeof(struct skl_cpr_cfg);
789*4882a593Smuzhiyun param_size += mconfig->formats_config.caps_size;
790*4882a593Smuzhiyun return param_size;
791*4882a593Smuzhiyun
792*4882a593Smuzhiyun case SKL_MODULE_TYPE_SRCINT:
793*4882a593Smuzhiyun return sizeof(struct skl_src_module_cfg);
794*4882a593Smuzhiyun
795*4882a593Smuzhiyun case SKL_MODULE_TYPE_UPDWMIX:
796*4882a593Smuzhiyun return sizeof(struct skl_up_down_mixer_cfg);
797*4882a593Smuzhiyun
798*4882a593Smuzhiyun case SKL_MODULE_TYPE_ALGO:
799*4882a593Smuzhiyun param_size = sizeof(struct skl_base_cfg);
800*4882a593Smuzhiyun param_size += mconfig->formats_config.caps_size;
801*4882a593Smuzhiyun return param_size;
802*4882a593Smuzhiyun
803*4882a593Smuzhiyun case SKL_MODULE_TYPE_BASE_OUTFMT:
804*4882a593Smuzhiyun case SKL_MODULE_TYPE_MIC_SELECT:
805*4882a593Smuzhiyun return sizeof(struct skl_base_outfmt_cfg);
806*4882a593Smuzhiyun
807*4882a593Smuzhiyun case SKL_MODULE_TYPE_MIXER:
808*4882a593Smuzhiyun case SKL_MODULE_TYPE_KPB:
809*4882a593Smuzhiyun return sizeof(struct skl_base_cfg);
810*4882a593Smuzhiyun
811*4882a593Smuzhiyun default:
812*4882a593Smuzhiyun /*
813*4882a593Smuzhiyun * return only base cfg when no specific module type is
814*4882a593Smuzhiyun * specified
815*4882a593Smuzhiyun */
816*4882a593Smuzhiyun return sizeof(struct skl_base_cfg);
817*4882a593Smuzhiyun }
818*4882a593Smuzhiyun
819*4882a593Smuzhiyun return 0;
820*4882a593Smuzhiyun }
821*4882a593Smuzhiyun
822*4882a593Smuzhiyun /*
823*4882a593Smuzhiyun * DSP firmware supports various modules like copier, SRC, updown etc.
824*4882a593Smuzhiyun * These modules required various parameters to be calculated and sent for
825*4882a593Smuzhiyun * the module initialization to DSP. By default a generic module needs only
826*4882a593Smuzhiyun * base module format configuration
827*4882a593Smuzhiyun */
828*4882a593Smuzhiyun
skl_set_module_format(struct skl_dev * skl,struct skl_module_cfg * module_config,u16 * module_config_size,void ** param_data)829*4882a593Smuzhiyun static int skl_set_module_format(struct skl_dev *skl,
830*4882a593Smuzhiyun struct skl_module_cfg *module_config,
831*4882a593Smuzhiyun u16 *module_config_size,
832*4882a593Smuzhiyun void **param_data)
833*4882a593Smuzhiyun {
834*4882a593Smuzhiyun u16 param_size;
835*4882a593Smuzhiyun
836*4882a593Smuzhiyun param_size = skl_get_module_param_size(skl, module_config);
837*4882a593Smuzhiyun
838*4882a593Smuzhiyun *param_data = kzalloc(param_size, GFP_KERNEL);
839*4882a593Smuzhiyun if (NULL == *param_data)
840*4882a593Smuzhiyun return -ENOMEM;
841*4882a593Smuzhiyun
842*4882a593Smuzhiyun *module_config_size = param_size;
843*4882a593Smuzhiyun
844*4882a593Smuzhiyun switch (module_config->m_type) {
845*4882a593Smuzhiyun case SKL_MODULE_TYPE_COPIER:
846*4882a593Smuzhiyun skl_set_copier_format(skl, module_config, *param_data);
847*4882a593Smuzhiyun break;
848*4882a593Smuzhiyun
849*4882a593Smuzhiyun case SKL_MODULE_TYPE_SRCINT:
850*4882a593Smuzhiyun skl_set_src_format(skl, module_config, *param_data);
851*4882a593Smuzhiyun break;
852*4882a593Smuzhiyun
853*4882a593Smuzhiyun case SKL_MODULE_TYPE_UPDWMIX:
854*4882a593Smuzhiyun skl_set_updown_mixer_format(skl, module_config, *param_data);
855*4882a593Smuzhiyun break;
856*4882a593Smuzhiyun
857*4882a593Smuzhiyun case SKL_MODULE_TYPE_ALGO:
858*4882a593Smuzhiyun skl_set_algo_format(skl, module_config, *param_data);
859*4882a593Smuzhiyun break;
860*4882a593Smuzhiyun
861*4882a593Smuzhiyun case SKL_MODULE_TYPE_BASE_OUTFMT:
862*4882a593Smuzhiyun case SKL_MODULE_TYPE_MIC_SELECT:
863*4882a593Smuzhiyun skl_set_base_outfmt_format(skl, module_config, *param_data);
864*4882a593Smuzhiyun break;
865*4882a593Smuzhiyun
866*4882a593Smuzhiyun case SKL_MODULE_TYPE_MIXER:
867*4882a593Smuzhiyun case SKL_MODULE_TYPE_KPB:
868*4882a593Smuzhiyun skl_set_base_module_format(skl, module_config, *param_data);
869*4882a593Smuzhiyun break;
870*4882a593Smuzhiyun
871*4882a593Smuzhiyun default:
872*4882a593Smuzhiyun skl_set_base_module_format(skl, module_config, *param_data);
873*4882a593Smuzhiyun break;
874*4882a593Smuzhiyun
875*4882a593Smuzhiyun }
876*4882a593Smuzhiyun
877*4882a593Smuzhiyun dev_dbg(skl->dev, "Module type=%d id=%d config size: %d bytes\n",
878*4882a593Smuzhiyun module_config->m_type, module_config->id.module_id,
879*4882a593Smuzhiyun param_size);
880*4882a593Smuzhiyun print_hex_dump_debug("Module params:", DUMP_PREFIX_OFFSET, 8, 4,
881*4882a593Smuzhiyun *param_data, param_size, false);
882*4882a593Smuzhiyun return 0;
883*4882a593Smuzhiyun }
884*4882a593Smuzhiyun
skl_get_queue_index(struct skl_module_pin * mpin,struct skl_module_inst_id id,int max)885*4882a593Smuzhiyun static int skl_get_queue_index(struct skl_module_pin *mpin,
886*4882a593Smuzhiyun struct skl_module_inst_id id, int max)
887*4882a593Smuzhiyun {
888*4882a593Smuzhiyun int i;
889*4882a593Smuzhiyun
890*4882a593Smuzhiyun for (i = 0; i < max; i++) {
891*4882a593Smuzhiyun if (mpin[i].id.module_id == id.module_id &&
892*4882a593Smuzhiyun mpin[i].id.instance_id == id.instance_id)
893*4882a593Smuzhiyun return i;
894*4882a593Smuzhiyun }
895*4882a593Smuzhiyun
896*4882a593Smuzhiyun return -EINVAL;
897*4882a593Smuzhiyun }
898*4882a593Smuzhiyun
899*4882a593Smuzhiyun /*
900*4882a593Smuzhiyun * Allocates queue for each module.
901*4882a593Smuzhiyun * if dynamic, the pin_index is allocated 0 to max_pin.
902*4882a593Smuzhiyun * In static, the pin_index is fixed based on module_id and instance id
903*4882a593Smuzhiyun */
skl_alloc_queue(struct skl_module_pin * mpin,struct skl_module_cfg * tgt_cfg,int max)904*4882a593Smuzhiyun static int skl_alloc_queue(struct skl_module_pin *mpin,
905*4882a593Smuzhiyun struct skl_module_cfg *tgt_cfg, int max)
906*4882a593Smuzhiyun {
907*4882a593Smuzhiyun int i;
908*4882a593Smuzhiyun struct skl_module_inst_id id = tgt_cfg->id;
909*4882a593Smuzhiyun /*
910*4882a593Smuzhiyun * if pin in dynamic, find first free pin
911*4882a593Smuzhiyun * otherwise find match module and instance id pin as topology will
912*4882a593Smuzhiyun * ensure a unique pin is assigned to this so no need to
913*4882a593Smuzhiyun * allocate/free
914*4882a593Smuzhiyun */
915*4882a593Smuzhiyun for (i = 0; i < max; i++) {
916*4882a593Smuzhiyun if (mpin[i].is_dynamic) {
917*4882a593Smuzhiyun if (!mpin[i].in_use &&
918*4882a593Smuzhiyun mpin[i].pin_state == SKL_PIN_UNBIND) {
919*4882a593Smuzhiyun
920*4882a593Smuzhiyun mpin[i].in_use = true;
921*4882a593Smuzhiyun mpin[i].id.module_id = id.module_id;
922*4882a593Smuzhiyun mpin[i].id.instance_id = id.instance_id;
923*4882a593Smuzhiyun mpin[i].id.pvt_id = id.pvt_id;
924*4882a593Smuzhiyun mpin[i].tgt_mcfg = tgt_cfg;
925*4882a593Smuzhiyun return i;
926*4882a593Smuzhiyun }
927*4882a593Smuzhiyun } else {
928*4882a593Smuzhiyun if (mpin[i].id.module_id == id.module_id &&
929*4882a593Smuzhiyun mpin[i].id.instance_id == id.instance_id &&
930*4882a593Smuzhiyun mpin[i].pin_state == SKL_PIN_UNBIND) {
931*4882a593Smuzhiyun
932*4882a593Smuzhiyun mpin[i].tgt_mcfg = tgt_cfg;
933*4882a593Smuzhiyun return i;
934*4882a593Smuzhiyun }
935*4882a593Smuzhiyun }
936*4882a593Smuzhiyun }
937*4882a593Smuzhiyun
938*4882a593Smuzhiyun return -EINVAL;
939*4882a593Smuzhiyun }
940*4882a593Smuzhiyun
skl_free_queue(struct skl_module_pin * mpin,int q_index)941*4882a593Smuzhiyun static void skl_free_queue(struct skl_module_pin *mpin, int q_index)
942*4882a593Smuzhiyun {
943*4882a593Smuzhiyun if (mpin[q_index].is_dynamic) {
944*4882a593Smuzhiyun mpin[q_index].in_use = false;
945*4882a593Smuzhiyun mpin[q_index].id.module_id = 0;
946*4882a593Smuzhiyun mpin[q_index].id.instance_id = 0;
947*4882a593Smuzhiyun mpin[q_index].id.pvt_id = 0;
948*4882a593Smuzhiyun }
949*4882a593Smuzhiyun mpin[q_index].pin_state = SKL_PIN_UNBIND;
950*4882a593Smuzhiyun mpin[q_index].tgt_mcfg = NULL;
951*4882a593Smuzhiyun }
952*4882a593Smuzhiyun
953*4882a593Smuzhiyun /* Module state will be set to unint, if all the out pin state is UNBIND */
954*4882a593Smuzhiyun
skl_clear_module_state(struct skl_module_pin * mpin,int max,struct skl_module_cfg * mcfg)955*4882a593Smuzhiyun static void skl_clear_module_state(struct skl_module_pin *mpin, int max,
956*4882a593Smuzhiyun struct skl_module_cfg *mcfg)
957*4882a593Smuzhiyun {
958*4882a593Smuzhiyun int i;
959*4882a593Smuzhiyun bool found = false;
960*4882a593Smuzhiyun
961*4882a593Smuzhiyun for (i = 0; i < max; i++) {
962*4882a593Smuzhiyun if (mpin[i].pin_state == SKL_PIN_UNBIND)
963*4882a593Smuzhiyun continue;
964*4882a593Smuzhiyun found = true;
965*4882a593Smuzhiyun break;
966*4882a593Smuzhiyun }
967*4882a593Smuzhiyun
968*4882a593Smuzhiyun if (!found)
969*4882a593Smuzhiyun mcfg->m_state = SKL_MODULE_INIT_DONE;
970*4882a593Smuzhiyun return;
971*4882a593Smuzhiyun }
972*4882a593Smuzhiyun
973*4882a593Smuzhiyun /*
974*4882a593Smuzhiyun * A module needs to be instanataited in DSP. A mdoule is present in a
975*4882a593Smuzhiyun * collection of module referred as a PIPE.
976*4882a593Smuzhiyun * We first calculate the module format, based on module type and then
977*4882a593Smuzhiyun * invoke the DSP by sending IPC INIT_INSTANCE using ipc helper
978*4882a593Smuzhiyun */
skl_init_module(struct skl_dev * skl,struct skl_module_cfg * mconfig)979*4882a593Smuzhiyun int skl_init_module(struct skl_dev *skl,
980*4882a593Smuzhiyun struct skl_module_cfg *mconfig)
981*4882a593Smuzhiyun {
982*4882a593Smuzhiyun u16 module_config_size = 0;
983*4882a593Smuzhiyun void *param_data = NULL;
984*4882a593Smuzhiyun int ret;
985*4882a593Smuzhiyun struct skl_ipc_init_instance_msg msg;
986*4882a593Smuzhiyun
987*4882a593Smuzhiyun dev_dbg(skl->dev, "%s: module_id = %d instance=%d\n", __func__,
988*4882a593Smuzhiyun mconfig->id.module_id, mconfig->id.pvt_id);
989*4882a593Smuzhiyun
990*4882a593Smuzhiyun if (mconfig->pipe->state != SKL_PIPE_CREATED) {
991*4882a593Smuzhiyun dev_err(skl->dev, "Pipe not created state= %d pipe_id= %d\n",
992*4882a593Smuzhiyun mconfig->pipe->state, mconfig->pipe->ppl_id);
993*4882a593Smuzhiyun return -EIO;
994*4882a593Smuzhiyun }
995*4882a593Smuzhiyun
996*4882a593Smuzhiyun ret = skl_set_module_format(skl, mconfig,
997*4882a593Smuzhiyun &module_config_size, ¶m_data);
998*4882a593Smuzhiyun if (ret < 0) {
999*4882a593Smuzhiyun dev_err(skl->dev, "Failed to set module format ret=%d\n", ret);
1000*4882a593Smuzhiyun return ret;
1001*4882a593Smuzhiyun }
1002*4882a593Smuzhiyun
1003*4882a593Smuzhiyun msg.module_id = mconfig->id.module_id;
1004*4882a593Smuzhiyun msg.instance_id = mconfig->id.pvt_id;
1005*4882a593Smuzhiyun msg.ppl_instance_id = mconfig->pipe->ppl_id;
1006*4882a593Smuzhiyun msg.param_data_size = module_config_size;
1007*4882a593Smuzhiyun msg.core_id = mconfig->core_id;
1008*4882a593Smuzhiyun msg.domain = mconfig->domain;
1009*4882a593Smuzhiyun
1010*4882a593Smuzhiyun ret = skl_ipc_init_instance(&skl->ipc, &msg, param_data);
1011*4882a593Smuzhiyun if (ret < 0) {
1012*4882a593Smuzhiyun dev_err(skl->dev, "Failed to init instance ret=%d\n", ret);
1013*4882a593Smuzhiyun kfree(param_data);
1014*4882a593Smuzhiyun return ret;
1015*4882a593Smuzhiyun }
1016*4882a593Smuzhiyun mconfig->m_state = SKL_MODULE_INIT_DONE;
1017*4882a593Smuzhiyun kfree(param_data);
1018*4882a593Smuzhiyun return ret;
1019*4882a593Smuzhiyun }
1020*4882a593Smuzhiyun
skl_dump_bind_info(struct skl_dev * skl,struct skl_module_cfg * src_module,struct skl_module_cfg * dst_module)1021*4882a593Smuzhiyun static void skl_dump_bind_info(struct skl_dev *skl, struct skl_module_cfg
1022*4882a593Smuzhiyun *src_module, struct skl_module_cfg *dst_module)
1023*4882a593Smuzhiyun {
1024*4882a593Smuzhiyun dev_dbg(skl->dev, "%s: src module_id = %d src_instance=%d\n",
1025*4882a593Smuzhiyun __func__, src_module->id.module_id, src_module->id.pvt_id);
1026*4882a593Smuzhiyun dev_dbg(skl->dev, "%s: dst_module=%d dst_instance=%d\n", __func__,
1027*4882a593Smuzhiyun dst_module->id.module_id, dst_module->id.pvt_id);
1028*4882a593Smuzhiyun
1029*4882a593Smuzhiyun dev_dbg(skl->dev, "src_module state = %d dst module state = %d\n",
1030*4882a593Smuzhiyun src_module->m_state, dst_module->m_state);
1031*4882a593Smuzhiyun }
1032*4882a593Smuzhiyun
1033*4882a593Smuzhiyun /*
1034*4882a593Smuzhiyun * On module freeup, we need to unbind the module with modules
1035*4882a593Smuzhiyun * it is already bind.
1036*4882a593Smuzhiyun * Find the pin allocated and unbind then using bind_unbind IPC
1037*4882a593Smuzhiyun */
skl_unbind_modules(struct skl_dev * skl,struct skl_module_cfg * src_mcfg,struct skl_module_cfg * dst_mcfg)1038*4882a593Smuzhiyun int skl_unbind_modules(struct skl_dev *skl,
1039*4882a593Smuzhiyun struct skl_module_cfg *src_mcfg,
1040*4882a593Smuzhiyun struct skl_module_cfg *dst_mcfg)
1041*4882a593Smuzhiyun {
1042*4882a593Smuzhiyun int ret;
1043*4882a593Smuzhiyun struct skl_ipc_bind_unbind_msg msg;
1044*4882a593Smuzhiyun struct skl_module_inst_id src_id = src_mcfg->id;
1045*4882a593Smuzhiyun struct skl_module_inst_id dst_id = dst_mcfg->id;
1046*4882a593Smuzhiyun int in_max = dst_mcfg->module->max_input_pins;
1047*4882a593Smuzhiyun int out_max = src_mcfg->module->max_output_pins;
1048*4882a593Smuzhiyun int src_index, dst_index, src_pin_state, dst_pin_state;
1049*4882a593Smuzhiyun
1050*4882a593Smuzhiyun skl_dump_bind_info(skl, src_mcfg, dst_mcfg);
1051*4882a593Smuzhiyun
1052*4882a593Smuzhiyun /* get src queue index */
1053*4882a593Smuzhiyun src_index = skl_get_queue_index(src_mcfg->m_out_pin, dst_id, out_max);
1054*4882a593Smuzhiyun if (src_index < 0)
1055*4882a593Smuzhiyun return 0;
1056*4882a593Smuzhiyun
1057*4882a593Smuzhiyun msg.src_queue = src_index;
1058*4882a593Smuzhiyun
1059*4882a593Smuzhiyun /* get dst queue index */
1060*4882a593Smuzhiyun dst_index = skl_get_queue_index(dst_mcfg->m_in_pin, src_id, in_max);
1061*4882a593Smuzhiyun if (dst_index < 0)
1062*4882a593Smuzhiyun return 0;
1063*4882a593Smuzhiyun
1064*4882a593Smuzhiyun msg.dst_queue = dst_index;
1065*4882a593Smuzhiyun
1066*4882a593Smuzhiyun src_pin_state = src_mcfg->m_out_pin[src_index].pin_state;
1067*4882a593Smuzhiyun dst_pin_state = dst_mcfg->m_in_pin[dst_index].pin_state;
1068*4882a593Smuzhiyun
1069*4882a593Smuzhiyun if (src_pin_state != SKL_PIN_BIND_DONE ||
1070*4882a593Smuzhiyun dst_pin_state != SKL_PIN_BIND_DONE)
1071*4882a593Smuzhiyun return 0;
1072*4882a593Smuzhiyun
1073*4882a593Smuzhiyun msg.module_id = src_mcfg->id.module_id;
1074*4882a593Smuzhiyun msg.instance_id = src_mcfg->id.pvt_id;
1075*4882a593Smuzhiyun msg.dst_module_id = dst_mcfg->id.module_id;
1076*4882a593Smuzhiyun msg.dst_instance_id = dst_mcfg->id.pvt_id;
1077*4882a593Smuzhiyun msg.bind = false;
1078*4882a593Smuzhiyun
1079*4882a593Smuzhiyun ret = skl_ipc_bind_unbind(&skl->ipc, &msg);
1080*4882a593Smuzhiyun if (!ret) {
1081*4882a593Smuzhiyun /* free queue only if unbind is success */
1082*4882a593Smuzhiyun skl_free_queue(src_mcfg->m_out_pin, src_index);
1083*4882a593Smuzhiyun skl_free_queue(dst_mcfg->m_in_pin, dst_index);
1084*4882a593Smuzhiyun
1085*4882a593Smuzhiyun /*
1086*4882a593Smuzhiyun * check only if src module bind state, bind is
1087*4882a593Smuzhiyun * always from src -> sink
1088*4882a593Smuzhiyun */
1089*4882a593Smuzhiyun skl_clear_module_state(src_mcfg->m_out_pin, out_max, src_mcfg);
1090*4882a593Smuzhiyun }
1091*4882a593Smuzhiyun
1092*4882a593Smuzhiyun return ret;
1093*4882a593Smuzhiyun }
1094*4882a593Smuzhiyun
fill_pin_params(struct skl_audio_data_format * pin_fmt,struct skl_module_fmt * format)1095*4882a593Smuzhiyun static void fill_pin_params(struct skl_audio_data_format *pin_fmt,
1096*4882a593Smuzhiyun struct skl_module_fmt *format)
1097*4882a593Smuzhiyun {
1098*4882a593Smuzhiyun pin_fmt->number_of_channels = format->channels;
1099*4882a593Smuzhiyun pin_fmt->s_freq = format->s_freq;
1100*4882a593Smuzhiyun pin_fmt->bit_depth = format->bit_depth;
1101*4882a593Smuzhiyun pin_fmt->valid_bit_depth = format->valid_bit_depth;
1102*4882a593Smuzhiyun pin_fmt->ch_cfg = format->ch_cfg;
1103*4882a593Smuzhiyun pin_fmt->sample_type = format->sample_type;
1104*4882a593Smuzhiyun pin_fmt->channel_map = format->ch_map;
1105*4882a593Smuzhiyun pin_fmt->interleaving = format->interleaving_style;
1106*4882a593Smuzhiyun }
1107*4882a593Smuzhiyun
1108*4882a593Smuzhiyun #define CPR_SINK_FMT_PARAM_ID 2
1109*4882a593Smuzhiyun
1110*4882a593Smuzhiyun /*
1111*4882a593Smuzhiyun * Once a module is instantiated it need to be 'bind' with other modules in
1112*4882a593Smuzhiyun * the pipeline. For binding we need to find the module pins which are bind
1113*4882a593Smuzhiyun * together
1114*4882a593Smuzhiyun * This function finds the pins and then sends bund_unbind IPC message to
1115*4882a593Smuzhiyun * DSP using IPC helper
1116*4882a593Smuzhiyun */
skl_bind_modules(struct skl_dev * skl,struct skl_module_cfg * src_mcfg,struct skl_module_cfg * dst_mcfg)1117*4882a593Smuzhiyun int skl_bind_modules(struct skl_dev *skl,
1118*4882a593Smuzhiyun struct skl_module_cfg *src_mcfg,
1119*4882a593Smuzhiyun struct skl_module_cfg *dst_mcfg)
1120*4882a593Smuzhiyun {
1121*4882a593Smuzhiyun int ret = 0;
1122*4882a593Smuzhiyun struct skl_ipc_bind_unbind_msg msg;
1123*4882a593Smuzhiyun int in_max = dst_mcfg->module->max_input_pins;
1124*4882a593Smuzhiyun int out_max = src_mcfg->module->max_output_pins;
1125*4882a593Smuzhiyun int src_index, dst_index;
1126*4882a593Smuzhiyun struct skl_module_fmt *format;
1127*4882a593Smuzhiyun struct skl_cpr_pin_fmt pin_fmt;
1128*4882a593Smuzhiyun struct skl_module *module;
1129*4882a593Smuzhiyun struct skl_module_iface *fmt;
1130*4882a593Smuzhiyun
1131*4882a593Smuzhiyun skl_dump_bind_info(skl, src_mcfg, dst_mcfg);
1132*4882a593Smuzhiyun
1133*4882a593Smuzhiyun if (src_mcfg->m_state < SKL_MODULE_INIT_DONE ||
1134*4882a593Smuzhiyun dst_mcfg->m_state < SKL_MODULE_INIT_DONE)
1135*4882a593Smuzhiyun return 0;
1136*4882a593Smuzhiyun
1137*4882a593Smuzhiyun src_index = skl_alloc_queue(src_mcfg->m_out_pin, dst_mcfg, out_max);
1138*4882a593Smuzhiyun if (src_index < 0)
1139*4882a593Smuzhiyun return -EINVAL;
1140*4882a593Smuzhiyun
1141*4882a593Smuzhiyun msg.src_queue = src_index;
1142*4882a593Smuzhiyun dst_index = skl_alloc_queue(dst_mcfg->m_in_pin, src_mcfg, in_max);
1143*4882a593Smuzhiyun if (dst_index < 0) {
1144*4882a593Smuzhiyun skl_free_queue(src_mcfg->m_out_pin, src_index);
1145*4882a593Smuzhiyun return -EINVAL;
1146*4882a593Smuzhiyun }
1147*4882a593Smuzhiyun
1148*4882a593Smuzhiyun /*
1149*4882a593Smuzhiyun * Copier module requires the separate large_config_set_ipc to
1150*4882a593Smuzhiyun * configure the pins other than 0
1151*4882a593Smuzhiyun */
1152*4882a593Smuzhiyun if (src_mcfg->m_type == SKL_MODULE_TYPE_COPIER && src_index > 0) {
1153*4882a593Smuzhiyun pin_fmt.sink_id = src_index;
1154*4882a593Smuzhiyun module = src_mcfg->module;
1155*4882a593Smuzhiyun fmt = &module->formats[src_mcfg->fmt_idx];
1156*4882a593Smuzhiyun
1157*4882a593Smuzhiyun /* Input fmt is same as that of src module input cfg */
1158*4882a593Smuzhiyun format = &fmt->inputs[0].fmt;
1159*4882a593Smuzhiyun fill_pin_params(&(pin_fmt.src_fmt), format);
1160*4882a593Smuzhiyun
1161*4882a593Smuzhiyun format = &fmt->outputs[src_index].fmt;
1162*4882a593Smuzhiyun fill_pin_params(&(pin_fmt.dst_fmt), format);
1163*4882a593Smuzhiyun ret = skl_set_module_params(skl, (void *)&pin_fmt,
1164*4882a593Smuzhiyun sizeof(struct skl_cpr_pin_fmt),
1165*4882a593Smuzhiyun CPR_SINK_FMT_PARAM_ID, src_mcfg);
1166*4882a593Smuzhiyun
1167*4882a593Smuzhiyun if (ret < 0)
1168*4882a593Smuzhiyun goto out;
1169*4882a593Smuzhiyun }
1170*4882a593Smuzhiyun
1171*4882a593Smuzhiyun msg.dst_queue = dst_index;
1172*4882a593Smuzhiyun
1173*4882a593Smuzhiyun dev_dbg(skl->dev, "src queue = %d dst queue =%d\n",
1174*4882a593Smuzhiyun msg.src_queue, msg.dst_queue);
1175*4882a593Smuzhiyun
1176*4882a593Smuzhiyun msg.module_id = src_mcfg->id.module_id;
1177*4882a593Smuzhiyun msg.instance_id = src_mcfg->id.pvt_id;
1178*4882a593Smuzhiyun msg.dst_module_id = dst_mcfg->id.module_id;
1179*4882a593Smuzhiyun msg.dst_instance_id = dst_mcfg->id.pvt_id;
1180*4882a593Smuzhiyun msg.bind = true;
1181*4882a593Smuzhiyun
1182*4882a593Smuzhiyun ret = skl_ipc_bind_unbind(&skl->ipc, &msg);
1183*4882a593Smuzhiyun
1184*4882a593Smuzhiyun if (!ret) {
1185*4882a593Smuzhiyun src_mcfg->m_state = SKL_MODULE_BIND_DONE;
1186*4882a593Smuzhiyun src_mcfg->m_out_pin[src_index].pin_state = SKL_PIN_BIND_DONE;
1187*4882a593Smuzhiyun dst_mcfg->m_in_pin[dst_index].pin_state = SKL_PIN_BIND_DONE;
1188*4882a593Smuzhiyun return ret;
1189*4882a593Smuzhiyun }
1190*4882a593Smuzhiyun out:
1191*4882a593Smuzhiyun /* error case , if IPC fails, clear the queue index */
1192*4882a593Smuzhiyun skl_free_queue(src_mcfg->m_out_pin, src_index);
1193*4882a593Smuzhiyun skl_free_queue(dst_mcfg->m_in_pin, dst_index);
1194*4882a593Smuzhiyun
1195*4882a593Smuzhiyun return ret;
1196*4882a593Smuzhiyun }
1197*4882a593Smuzhiyun
skl_set_pipe_state(struct skl_dev * skl,struct skl_pipe * pipe,enum skl_ipc_pipeline_state state)1198*4882a593Smuzhiyun static int skl_set_pipe_state(struct skl_dev *skl, struct skl_pipe *pipe,
1199*4882a593Smuzhiyun enum skl_ipc_pipeline_state state)
1200*4882a593Smuzhiyun {
1201*4882a593Smuzhiyun dev_dbg(skl->dev, "%s: pipe_state = %d\n", __func__, state);
1202*4882a593Smuzhiyun
1203*4882a593Smuzhiyun return skl_ipc_set_pipeline_state(&skl->ipc, pipe->ppl_id, state);
1204*4882a593Smuzhiyun }
1205*4882a593Smuzhiyun
1206*4882a593Smuzhiyun /*
1207*4882a593Smuzhiyun * A pipeline is a collection of modules. Before a module in instantiated a
1208*4882a593Smuzhiyun * pipeline needs to be created for it.
1209*4882a593Smuzhiyun * This function creates pipeline, by sending create pipeline IPC messages
1210*4882a593Smuzhiyun * to FW
1211*4882a593Smuzhiyun */
skl_create_pipeline(struct skl_dev * skl,struct skl_pipe * pipe)1212*4882a593Smuzhiyun int skl_create_pipeline(struct skl_dev *skl, struct skl_pipe *pipe)
1213*4882a593Smuzhiyun {
1214*4882a593Smuzhiyun int ret;
1215*4882a593Smuzhiyun
1216*4882a593Smuzhiyun dev_dbg(skl->dev, "%s: pipe_id = %d\n", __func__, pipe->ppl_id);
1217*4882a593Smuzhiyun
1218*4882a593Smuzhiyun ret = skl_ipc_create_pipeline(&skl->ipc, pipe->memory_pages,
1219*4882a593Smuzhiyun pipe->pipe_priority, pipe->ppl_id,
1220*4882a593Smuzhiyun pipe->lp_mode);
1221*4882a593Smuzhiyun if (ret < 0) {
1222*4882a593Smuzhiyun dev_err(skl->dev, "Failed to create pipeline\n");
1223*4882a593Smuzhiyun return ret;
1224*4882a593Smuzhiyun }
1225*4882a593Smuzhiyun
1226*4882a593Smuzhiyun pipe->state = SKL_PIPE_CREATED;
1227*4882a593Smuzhiyun
1228*4882a593Smuzhiyun return 0;
1229*4882a593Smuzhiyun }
1230*4882a593Smuzhiyun
1231*4882a593Smuzhiyun /*
1232*4882a593Smuzhiyun * A pipeline needs to be deleted on cleanup. If a pipeline is running,
1233*4882a593Smuzhiyun * then pause it first. Before actual deletion, pipeline should enter
1234*4882a593Smuzhiyun * reset state. Finish the procedure by sending delete pipeline IPC.
1235*4882a593Smuzhiyun * DSP will stop the DMA engines and release resources
1236*4882a593Smuzhiyun */
skl_delete_pipe(struct skl_dev * skl,struct skl_pipe * pipe)1237*4882a593Smuzhiyun int skl_delete_pipe(struct skl_dev *skl, struct skl_pipe *pipe)
1238*4882a593Smuzhiyun {
1239*4882a593Smuzhiyun int ret;
1240*4882a593Smuzhiyun
1241*4882a593Smuzhiyun dev_dbg(skl->dev, "%s: pipe = %d\n", __func__, pipe->ppl_id);
1242*4882a593Smuzhiyun
1243*4882a593Smuzhiyun /* If pipe was not created in FW, do not try to delete it */
1244*4882a593Smuzhiyun if (pipe->state < SKL_PIPE_CREATED)
1245*4882a593Smuzhiyun return 0;
1246*4882a593Smuzhiyun
1247*4882a593Smuzhiyun /* If pipe is started, do stop the pipe in FW. */
1248*4882a593Smuzhiyun if (pipe->state >= SKL_PIPE_STARTED) {
1249*4882a593Smuzhiyun ret = skl_set_pipe_state(skl, pipe, PPL_PAUSED);
1250*4882a593Smuzhiyun if (ret < 0) {
1251*4882a593Smuzhiyun dev_err(skl->dev, "Failed to stop pipeline\n");
1252*4882a593Smuzhiyun return ret;
1253*4882a593Smuzhiyun }
1254*4882a593Smuzhiyun
1255*4882a593Smuzhiyun pipe->state = SKL_PIPE_PAUSED;
1256*4882a593Smuzhiyun }
1257*4882a593Smuzhiyun
1258*4882a593Smuzhiyun /* reset pipe state before deletion */
1259*4882a593Smuzhiyun ret = skl_set_pipe_state(skl, pipe, PPL_RESET);
1260*4882a593Smuzhiyun if (ret < 0) {
1261*4882a593Smuzhiyun dev_err(skl->dev, "Failed to reset pipe ret=%d\n", ret);
1262*4882a593Smuzhiyun return ret;
1263*4882a593Smuzhiyun }
1264*4882a593Smuzhiyun
1265*4882a593Smuzhiyun pipe->state = SKL_PIPE_RESET;
1266*4882a593Smuzhiyun
1267*4882a593Smuzhiyun ret = skl_ipc_delete_pipeline(&skl->ipc, pipe->ppl_id);
1268*4882a593Smuzhiyun if (ret < 0) {
1269*4882a593Smuzhiyun dev_err(skl->dev, "Failed to delete pipeline\n");
1270*4882a593Smuzhiyun return ret;
1271*4882a593Smuzhiyun }
1272*4882a593Smuzhiyun
1273*4882a593Smuzhiyun pipe->state = SKL_PIPE_INVALID;
1274*4882a593Smuzhiyun
1275*4882a593Smuzhiyun return ret;
1276*4882a593Smuzhiyun }
1277*4882a593Smuzhiyun
1278*4882a593Smuzhiyun /*
1279*4882a593Smuzhiyun * A pipeline is also a scheduling entity in DSP which can be run, stopped
1280*4882a593Smuzhiyun * For processing data the pipe need to be run by sending IPC set pipe state
1281*4882a593Smuzhiyun * to DSP
1282*4882a593Smuzhiyun */
skl_run_pipe(struct skl_dev * skl,struct skl_pipe * pipe)1283*4882a593Smuzhiyun int skl_run_pipe(struct skl_dev *skl, struct skl_pipe *pipe)
1284*4882a593Smuzhiyun {
1285*4882a593Smuzhiyun int ret;
1286*4882a593Smuzhiyun
1287*4882a593Smuzhiyun dev_dbg(skl->dev, "%s: pipe = %d\n", __func__, pipe->ppl_id);
1288*4882a593Smuzhiyun
1289*4882a593Smuzhiyun /* If pipe was not created in FW, do not try to pause or delete */
1290*4882a593Smuzhiyun if (pipe->state < SKL_PIPE_CREATED)
1291*4882a593Smuzhiyun return 0;
1292*4882a593Smuzhiyun
1293*4882a593Smuzhiyun /* Pipe has to be paused before it is started */
1294*4882a593Smuzhiyun ret = skl_set_pipe_state(skl, pipe, PPL_PAUSED);
1295*4882a593Smuzhiyun if (ret < 0) {
1296*4882a593Smuzhiyun dev_err(skl->dev, "Failed to pause pipe\n");
1297*4882a593Smuzhiyun return ret;
1298*4882a593Smuzhiyun }
1299*4882a593Smuzhiyun
1300*4882a593Smuzhiyun pipe->state = SKL_PIPE_PAUSED;
1301*4882a593Smuzhiyun
1302*4882a593Smuzhiyun ret = skl_set_pipe_state(skl, pipe, PPL_RUNNING);
1303*4882a593Smuzhiyun if (ret < 0) {
1304*4882a593Smuzhiyun dev_err(skl->dev, "Failed to start pipe\n");
1305*4882a593Smuzhiyun return ret;
1306*4882a593Smuzhiyun }
1307*4882a593Smuzhiyun
1308*4882a593Smuzhiyun pipe->state = SKL_PIPE_STARTED;
1309*4882a593Smuzhiyun
1310*4882a593Smuzhiyun return 0;
1311*4882a593Smuzhiyun }
1312*4882a593Smuzhiyun
1313*4882a593Smuzhiyun /*
1314*4882a593Smuzhiyun * Stop the pipeline by sending set pipe state IPC
1315*4882a593Smuzhiyun * DSP doesnt implement stop so we always send pause message
1316*4882a593Smuzhiyun */
skl_stop_pipe(struct skl_dev * skl,struct skl_pipe * pipe)1317*4882a593Smuzhiyun int skl_stop_pipe(struct skl_dev *skl, struct skl_pipe *pipe)
1318*4882a593Smuzhiyun {
1319*4882a593Smuzhiyun int ret;
1320*4882a593Smuzhiyun
1321*4882a593Smuzhiyun dev_dbg(skl->dev, "In %s pipe=%d\n", __func__, pipe->ppl_id);
1322*4882a593Smuzhiyun
1323*4882a593Smuzhiyun /* If pipe was not created in FW, do not try to pause or delete */
1324*4882a593Smuzhiyun if (pipe->state < SKL_PIPE_PAUSED)
1325*4882a593Smuzhiyun return 0;
1326*4882a593Smuzhiyun
1327*4882a593Smuzhiyun ret = skl_set_pipe_state(skl, pipe, PPL_PAUSED);
1328*4882a593Smuzhiyun if (ret < 0) {
1329*4882a593Smuzhiyun dev_dbg(skl->dev, "Failed to stop pipe\n");
1330*4882a593Smuzhiyun return ret;
1331*4882a593Smuzhiyun }
1332*4882a593Smuzhiyun
1333*4882a593Smuzhiyun pipe->state = SKL_PIPE_PAUSED;
1334*4882a593Smuzhiyun
1335*4882a593Smuzhiyun return 0;
1336*4882a593Smuzhiyun }
1337*4882a593Smuzhiyun
1338*4882a593Smuzhiyun /*
1339*4882a593Smuzhiyun * Reset the pipeline by sending set pipe state IPC this will reset the DMA
1340*4882a593Smuzhiyun * from the DSP side
1341*4882a593Smuzhiyun */
skl_reset_pipe(struct skl_dev * skl,struct skl_pipe * pipe)1342*4882a593Smuzhiyun int skl_reset_pipe(struct skl_dev *skl, struct skl_pipe *pipe)
1343*4882a593Smuzhiyun {
1344*4882a593Smuzhiyun int ret;
1345*4882a593Smuzhiyun
1346*4882a593Smuzhiyun /* If pipe was not created in FW, do not try to pause or delete */
1347*4882a593Smuzhiyun if (pipe->state < SKL_PIPE_PAUSED)
1348*4882a593Smuzhiyun return 0;
1349*4882a593Smuzhiyun
1350*4882a593Smuzhiyun ret = skl_set_pipe_state(skl, pipe, PPL_RESET);
1351*4882a593Smuzhiyun if (ret < 0) {
1352*4882a593Smuzhiyun dev_dbg(skl->dev, "Failed to reset pipe ret=%d\n", ret);
1353*4882a593Smuzhiyun return ret;
1354*4882a593Smuzhiyun }
1355*4882a593Smuzhiyun
1356*4882a593Smuzhiyun pipe->state = SKL_PIPE_RESET;
1357*4882a593Smuzhiyun
1358*4882a593Smuzhiyun return 0;
1359*4882a593Smuzhiyun }
1360*4882a593Smuzhiyun
1361*4882a593Smuzhiyun /* Algo parameter set helper function */
skl_set_module_params(struct skl_dev * skl,u32 * params,int size,u32 param_id,struct skl_module_cfg * mcfg)1362*4882a593Smuzhiyun int skl_set_module_params(struct skl_dev *skl, u32 *params, int size,
1363*4882a593Smuzhiyun u32 param_id, struct skl_module_cfg *mcfg)
1364*4882a593Smuzhiyun {
1365*4882a593Smuzhiyun struct skl_ipc_large_config_msg msg;
1366*4882a593Smuzhiyun
1367*4882a593Smuzhiyun msg.module_id = mcfg->id.module_id;
1368*4882a593Smuzhiyun msg.instance_id = mcfg->id.pvt_id;
1369*4882a593Smuzhiyun msg.param_data_size = size;
1370*4882a593Smuzhiyun msg.large_param_id = param_id;
1371*4882a593Smuzhiyun
1372*4882a593Smuzhiyun return skl_ipc_set_large_config(&skl->ipc, &msg, params);
1373*4882a593Smuzhiyun }
1374*4882a593Smuzhiyun
skl_get_module_params(struct skl_dev * skl,u32 * params,int size,u32 param_id,struct skl_module_cfg * mcfg)1375*4882a593Smuzhiyun int skl_get_module_params(struct skl_dev *skl, u32 *params, int size,
1376*4882a593Smuzhiyun u32 param_id, struct skl_module_cfg *mcfg)
1377*4882a593Smuzhiyun {
1378*4882a593Smuzhiyun struct skl_ipc_large_config_msg msg;
1379*4882a593Smuzhiyun size_t bytes = size;
1380*4882a593Smuzhiyun
1381*4882a593Smuzhiyun msg.module_id = mcfg->id.module_id;
1382*4882a593Smuzhiyun msg.instance_id = mcfg->id.pvt_id;
1383*4882a593Smuzhiyun msg.param_data_size = size;
1384*4882a593Smuzhiyun msg.large_param_id = param_id;
1385*4882a593Smuzhiyun
1386*4882a593Smuzhiyun return skl_ipc_get_large_config(&skl->ipc, &msg, ¶ms, &bytes);
1387*4882a593Smuzhiyun }
1388