Lines Matching +full:fw +full:- +full:cfg +full:- +full:mmio

1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
5 // Author: Allen-KH Cheng <allen-kh.cheng@mediatek.com>
24 #include "../../sof-of-dev.h"
25 #include "../../sof-audio.h"
28 #include "mt8186-clk.h"
43 struct adsp_priv *priv = sdev->pdata->hw_pdata; in mt8186_send_msg()
45 sof_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data, in mt8186_send_msg()
46 msg->msg_size); in mt8186_send_msg()
48 return mtk_adsp_ipc_send(priv->dsp_ipc, MTK_ADSP_IPC_REQ, MTK_ADSP_IPC_OP_REQ); in mt8186_send_msg()
53 struct snd_sof_ipc_msg *msg = sdev->msg; in mt8186_get_reply()
58 dev_warn(sdev->dev, "unexpected ipc interrupt\n"); in mt8186_get_reply()
63 sof_mailbox_read(sdev, sdev->host_box.offset, &reply, sizeof(reply)); in mt8186_get_reply()
65 memcpy(msg->reply_data, &reply, sizeof(reply)); in mt8186_get_reply()
69 if (reply.hdr.size != msg->reply_size) { in mt8186_get_reply()
70 dev_err(sdev->dev, "error: reply expected %zu got %u bytes\n", in mt8186_get_reply()
71 msg->reply_size, reply.hdr.size); in mt8186_get_reply()
72 ret = -EINVAL; in mt8186_get_reply()
76 if (msg->reply_size > 0) in mt8186_get_reply()
77 sof_mailbox_read(sdev, sdev->host_box.offset, in mt8186_get_reply()
78 msg->reply_data, msg->reply_size); in mt8186_get_reply()
81 msg->reply_error = ret; in mt8186_get_reply()
89 spin_lock_irqsave(&priv->sdev->ipc_lock, flags); in mt8186_dsp_handle_reply()
90 mt8186_get_reply(priv->sdev); in mt8186_dsp_handle_reply()
91 snd_sof_ipc_reply(priv->sdev, 0); in mt8186_dsp_handle_reply()
92 spin_unlock_irqrestore(&priv->sdev->ipc_lock, flags); in mt8186_dsp_handle_reply()
102 sof_mailbox_read(priv->sdev, priv->sdev->debug_box.offset + 4, in mt8186_dsp_handle_request()
107 snd_sof_dsp_panic(priv->sdev, p, true); in mt8186_dsp_handle_request()
109 snd_sof_ipc_msgs_rx(priv->sdev); in mt8186_dsp_handle_request()
112 ret = mtk_adsp_ipc_send(priv->dsp_ipc, MTK_ADSP_IPC_RSP, MTK_ADSP_IPC_OP_RSP); in mt8186_dsp_handle_request()
114 dev_err(priv->dev, "request send ipc failed"); in mt8186_dsp_handle_request()
125 struct resource *mmio; in platform_parse_resource() local
128 struct device *dev = &pdev->dev; in platform_parse_resource()
132 mem_region = of_parse_phandle(dev->of_node, "memory-region", 0); in platform_parse_resource()
134 dev_err(dev, "no dma memory-region phandle\n"); in platform_parse_resource()
135 return -ENODEV; in platform_parse_resource()
153 mem_region = of_parse_phandle(dev->of_node, "memory-region", 1); in platform_parse_resource()
155 dev_err(dev, "no memory-region sysmem phandle\n"); in platform_parse_resource()
156 return -ENODEV; in platform_parse_resource()
166 adsp->pa_dram = (phys_addr_t)res.start; in platform_parse_resource()
167 if (adsp->pa_dram & DRAM_REMAP_MASK) { in platform_parse_resource()
168 dev_err(dev, "adsp memory(%#x) is not 4K-aligned\n", in platform_parse_resource()
169 (u32)adsp->pa_dram); in platform_parse_resource()
170 return -EINVAL; in platform_parse_resource()
173 adsp->dramsize = resource_size(&res); in platform_parse_resource()
174 if (adsp->dramsize < TOTAL_SIZE_SHARED_DRAM_FROM_TAIL) { in platform_parse_resource()
176 adsp->dramsize); in platform_parse_resource()
177 return -EINVAL; in platform_parse_resource()
180 dev_dbg(dev, "dram pbase=%pa size=%#x\n", &adsp->pa_dram, adsp->dramsize); in platform_parse_resource()
182 mmio = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg"); in platform_parse_resource()
183 if (!mmio) { in platform_parse_resource()
184 dev_err(dev, "no ADSP-CFG register resource\n"); in platform_parse_resource()
185 return -ENXIO; in platform_parse_resource()
188 adsp->va_cfgreg = devm_ioremap_resource(dev, mmio); in platform_parse_resource()
189 if (IS_ERR(adsp->va_cfgreg)) in platform_parse_resource()
190 return PTR_ERR(adsp->va_cfgreg); in platform_parse_resource()
192 adsp->pa_cfgreg = (phys_addr_t)mmio->start; in platform_parse_resource()
193 adsp->cfgregsize = resource_size(mmio); in platform_parse_resource()
195 dev_dbg(dev, "cfgreg pbase=%pa size=%#x\n", &adsp->pa_cfgreg, adsp->cfgregsize); in platform_parse_resource()
197 mmio = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sram"); in platform_parse_resource()
198 if (!mmio) { in platform_parse_resource()
200 return -ENXIO; in platform_parse_resource()
203 adsp->pa_sram = (phys_addr_t)mmio->start; in platform_parse_resource()
204 adsp->sramsize = resource_size(mmio); in platform_parse_resource()
206 dev_dbg(dev, "sram pbase=%pa size=%#x\n", &adsp->pa_sram, adsp->sramsize); in platform_parse_resource()
208 mmio = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sec"); in platform_parse_resource()
209 if (!mmio) { in platform_parse_resource()
211 return -ENXIO; in platform_parse_resource()
214 adsp->va_secreg = devm_ioremap_resource(dev, mmio); in platform_parse_resource()
215 if (IS_ERR(adsp->va_secreg)) in platform_parse_resource()
216 return PTR_ERR(adsp->va_secreg); in platform_parse_resource()
218 adsp->pa_secreg = (phys_addr_t)mmio->start; in platform_parse_resource()
219 adsp->secregsize = resource_size(mmio); in platform_parse_resource()
221 dev_dbg(dev, "secreg pbase=%pa size=%#x\n", &adsp->pa_secreg, adsp->secregsize); in platform_parse_resource()
223 mmio = platform_get_resource_byname(pdev, IORESOURCE_MEM, "bus"); in platform_parse_resource()
224 if (!mmio) { in platform_parse_resource()
226 return -ENXIO; in platform_parse_resource()
229 adsp->va_busreg = devm_ioremap_resource(dev, mmio); in platform_parse_resource()
230 if (IS_ERR(adsp->va_busreg)) in platform_parse_resource()
231 return PTR_ERR(adsp->va_busreg); in platform_parse_resource()
233 adsp->pa_busreg = (phys_addr_t)mmio->start; in platform_parse_resource()
234 adsp->busregsize = resource_size(mmio); in platform_parse_resource()
236 dev_dbg(dev, "busreg pbase=%pa size=%#x\n", &adsp->pa_busreg, adsp->busregsize); in platform_parse_resource()
258 offset = adsp->pa_dram - DRAM_PHYS_BASE_FROM_DSP_VIEW; in adsp_memory_remap_init()
259 adsp->dram_offset = offset; in adsp_memory_remap_init()
262 dev_dbg(sdev->dev, "adsp->pa_dram %pa, offset %#x\n", &adsp->pa_dram, offset); in adsp_memory_remap_init()
269 dev_err(sdev->dev, "emi remap fail\n"); in adsp_memory_remap_init()
270 return -EIO; in adsp_memory_remap_init()
278 struct device *dev = &pdev->dev; in adsp_shared_base_ioremap()
282 /* remap shared-dram base to be non-cachable */ in adsp_shared_base_ioremap()
284 adsp->pa_shared_dram = adsp->pa_dram + adsp->dramsize - shared_size; in adsp_shared_base_ioremap()
285 if (adsp->va_dram) { in adsp_shared_base_ioremap()
286 adsp->shared_dram = adsp->va_dram + DSP_DRAM_SIZE - shared_size; in adsp_shared_base_ioremap()
288 adsp->shared_dram = devm_ioremap(dev, adsp->pa_shared_dram, in adsp_shared_base_ioremap()
290 if (!adsp->shared_dram) { in adsp_shared_base_ioremap()
292 return -ENOMEM; in adsp_shared_base_ioremap()
295 dev_dbg(dev, "shared-dram vbase=%p, phy addr :%pa, size=%#x\n", in adsp_shared_base_ioremap()
296 adsp->shared_dram, &adsp->pa_shared_dram, shared_size); in adsp_shared_base_ioremap()
306 dev_dbg(sdev->dev, "HIFIxDSP boot from base : 0x%08X\n", adsp_bootup_addr); in mt8186_run()
314 struct platform_device *pdev = container_of(sdev->dev, struct platform_device, dev); in mt8186_dsp_probe()
318 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in mt8186_dsp_probe()
320 return -ENOMEM; in mt8186_dsp_probe()
322 sdev->pdata->hw_pdata = priv; in mt8186_dsp_probe()
323 priv->dev = sdev->dev; in mt8186_dsp_probe()
324 priv->sdev = sdev; in mt8186_dsp_probe()
326 priv->adsp = devm_kzalloc(&pdev->dev, sizeof(struct mtk_adsp_chip_info), GFP_KERNEL); in mt8186_dsp_probe()
327 if (!priv->adsp) in mt8186_dsp_probe()
328 return -ENOMEM; in mt8186_dsp_probe()
330 ret = platform_parse_resource(pdev, priv->adsp); in mt8186_dsp_probe()
334 sdev->bar[SOF_FW_BLK_TYPE_IRAM] = devm_ioremap(sdev->dev, in mt8186_dsp_probe()
335 priv->adsp->pa_sram, in mt8186_dsp_probe()
336 priv->adsp->sramsize); in mt8186_dsp_probe()
337 if (!sdev->bar[SOF_FW_BLK_TYPE_IRAM]) { in mt8186_dsp_probe()
338 dev_err(sdev->dev, "failed to ioremap base %pa size %#x\n", in mt8186_dsp_probe()
339 &priv->adsp->pa_sram, priv->adsp->sramsize); in mt8186_dsp_probe()
340 return -ENOMEM; in mt8186_dsp_probe()
343 sdev->bar[SOF_FW_BLK_TYPE_SRAM] = devm_ioremap_wc(sdev->dev, in mt8186_dsp_probe()
344 priv->adsp->pa_dram, in mt8186_dsp_probe()
345 priv->adsp->dramsize); in mt8186_dsp_probe()
346 if (!sdev->bar[SOF_FW_BLK_TYPE_SRAM]) { in mt8186_dsp_probe()
347 dev_err(sdev->dev, "failed to ioremap base %pa size %#x\n", in mt8186_dsp_probe()
348 &priv->adsp->pa_dram, priv->adsp->dramsize); in mt8186_dsp_probe()
349 return -ENOMEM; in mt8186_dsp_probe()
352 priv->adsp->va_dram = sdev->bar[SOF_FW_BLK_TYPE_SRAM]; in mt8186_dsp_probe()
354 ret = adsp_shared_base_ioremap(pdev, priv->adsp); in mt8186_dsp_probe()
356 dev_err(sdev->dev, "adsp_shared_base_ioremap fail!\n"); in mt8186_dsp_probe()
360 sdev->bar[DSP_REG_BAR] = priv->adsp->va_cfgreg; in mt8186_dsp_probe()
361 sdev->bar[DSP_SECREG_BAR] = priv->adsp->va_secreg; in mt8186_dsp_probe()
362 sdev->bar[DSP_BUSREG_BAR] = priv->adsp->va_busreg; in mt8186_dsp_probe()
364 sdev->mmio_bar = SOF_FW_BLK_TYPE_SRAM; in mt8186_dsp_probe()
365 sdev->mailbox_bar = SOF_FW_BLK_TYPE_SRAM; in mt8186_dsp_probe()
367 /* set default mailbox offset for FW ready message */ in mt8186_dsp_probe()
368 sdev->dsp_box.offset = mt8186_get_mailbox_offset(sdev); in mt8186_dsp_probe()
370 ret = adsp_memory_remap_init(sdev, priv->adsp); in mt8186_dsp_probe()
372 dev_err(sdev->dev, "adsp_memory_remap_init fail!\n"); in mt8186_dsp_probe()
379 dev_err(sdev->dev, "mt8186_adsp_init_clock failed\n"); in mt8186_dsp_probe()
385 dev_err(sdev->dev, "mt8186_adsp_clock_on fail!\n"); in mt8186_dsp_probe()
391 priv->ipc_dev = platform_device_register_data(&pdev->dev, "mtk-adsp-ipc", in mt8186_dsp_probe()
394 if (IS_ERR(priv->ipc_dev)) { in mt8186_dsp_probe()
395 ret = PTR_ERR(priv->ipc_dev); in mt8186_dsp_probe()
396 dev_err(sdev->dev, "failed to create mtk-adsp-ipc device\n"); in mt8186_dsp_probe()
400 priv->dsp_ipc = dev_get_drvdata(&priv->ipc_dev->dev); in mt8186_dsp_probe()
401 if (!priv->dsp_ipc) { in mt8186_dsp_probe()
402 ret = -EPROBE_DEFER; in mt8186_dsp_probe()
403 dev_err(sdev->dev, "failed to get drvdata\n"); in mt8186_dsp_probe()
407 mtk_adsp_ipc_set_data(priv->dsp_ipc, priv); in mt8186_dsp_probe()
408 priv->dsp_ipc->ops = &dsp_ops; in mt8186_dsp_probe()
413 platform_device_unregister(priv->ipc_dev); in mt8186_dsp_probe()
423 struct adsp_priv *priv = sdev->pdata->hw_pdata; in mt8186_dsp_remove()
425 platform_device_unregister(priv->ipc_dev); in mt8186_dsp_remove()
448 dev_err(sdev->dev, "mt8186_adsp_clock_on fail!\n"); in mt8186_dsp_resume()
468 platform_params->cont_update_posn = 1; in mt8186_pcm_hw_params()
481 struct snd_soc_component *scomp = sdev->component; in mt8186_pcm_pointer()
486 dev_warn_ratelimited(sdev->dev, "warn: can't find PCM with DAI ID %d\n", in mt8186_pcm_pointer()
487 rtd->dai_link->id); in mt8186_pcm_pointer()
491 stream = &spcm->stream[substream->stream]; in mt8186_pcm_pointer()
492 ret = snd_sof_ipc_msg_data(sdev, stream->substream, &posn, sizeof(posn)); in mt8186_pcm_pointer()
494 dev_warn(sdev->dev, "failed to read stream position: %d\n", ret); in mt8186_pcm_pointer()
498 memcpy(&stream->posn, &posn, sizeof(posn)); in mt8186_pcm_pointer()
499 pos = spcm->stream[substream->stream].posn.host_posn; in mt8186_pcm_pointer()
500 pos = bytes_to_frames(substream->runtime, pos); in mt8186_pcm_pointer()
600 .sof_tplg_filename = "sof-mt8186.tplg",
613 [SOF_IPC] = "mediatek/sof-tplg",
616 [SOF_IPC] = "sof-mt8186.ri",
618 .nocodec_tplg_filename = "sof-mt8186-nocodec.tplg",
623 { .compatible = "mediatek,mt8186-dsp", .data = &sof_of_mt8186_desc},
633 .name = "sof-audio-of-mt8186",