Lines Matching +full:fw +full:- +full:cfg +full:- +full:mmio
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
24 #include "../../sof-of-dev.h"
25 #include "../../sof-audio.h"
27 #include "../mtk-adsp-common.h"
29 #include "mt8195-clk.h"
44 struct adsp_priv *priv = sdev->pdata->hw_pdata; in mt8195_send_msg()
46 sof_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data, in mt8195_send_msg()
47 msg->msg_size); in mt8195_send_msg()
49 return mtk_adsp_ipc_send(priv->dsp_ipc, MTK_ADSP_IPC_REQ, MTK_ADSP_IPC_OP_REQ); in mt8195_send_msg()
54 struct snd_sof_ipc_msg *msg = sdev->msg; in mt8195_get_reply()
59 dev_warn(sdev->dev, "unexpected ipc interrupt\n"); in mt8195_get_reply()
64 sof_mailbox_read(sdev, sdev->host_box.offset, &reply, sizeof(reply)); in mt8195_get_reply()
66 memcpy(msg->reply_data, &reply, sizeof(reply)); in mt8195_get_reply()
70 if (reply.hdr.size != msg->reply_size) { in mt8195_get_reply()
71 dev_err(sdev->dev, "error: reply expected %zu got %u bytes\n", in mt8195_get_reply()
72 msg->reply_size, reply.hdr.size); in mt8195_get_reply()
73 ret = -EINVAL; in mt8195_get_reply()
77 if (msg->reply_size > 0) in mt8195_get_reply()
78 sof_mailbox_read(sdev, sdev->host_box.offset, in mt8195_get_reply()
79 msg->reply_data, msg->reply_size); in mt8195_get_reply()
82 msg->reply_error = ret; in mt8195_get_reply()
90 spin_lock_irqsave(&priv->sdev->ipc_lock, flags); in mt8195_dsp_handle_reply()
91 mt8195_get_reply(priv->sdev); in mt8195_dsp_handle_reply()
92 snd_sof_ipc_reply(priv->sdev, 0); in mt8195_dsp_handle_reply()
93 spin_unlock_irqrestore(&priv->sdev->ipc_lock, flags); in mt8195_dsp_handle_reply()
103 sof_mailbox_read(priv->sdev, priv->sdev->debug_box.offset + 4, in mt8195_dsp_handle_request()
108 snd_sof_dsp_panic(priv->sdev, p, true); in mt8195_dsp_handle_request()
110 snd_sof_ipc_msgs_rx(priv->sdev); in mt8195_dsp_handle_request()
113 ret = mtk_adsp_ipc_send(priv->dsp_ipc, MTK_ADSP_IPC_RSP, MTK_ADSP_IPC_OP_RSP); in mt8195_dsp_handle_request()
115 dev_err(priv->dev, "request send ipc failed"); in mt8195_dsp_handle_request()
126 struct resource *mmio; in platform_parse_resource() local
129 struct device *dev = &pdev->dev; in platform_parse_resource()
133 mem_region = of_parse_phandle(dev->of_node, "memory-region", 0); in platform_parse_resource()
135 dev_err(dev, "no dma memory-region phandle\n"); in platform_parse_resource()
136 return -ENODEV; in platform_parse_resource()
148 adsp->pa_shared_dram = (phys_addr_t)res.start; in platform_parse_resource()
149 adsp->shared_size = resource_size(&res); in platform_parse_resource()
150 if (adsp->pa_shared_dram & DRAM_REMAP_MASK) { in platform_parse_resource()
151 dev_err(dev, "adsp shared dma memory(%#x) is not 4K-aligned\n", in platform_parse_resource()
152 (u32)adsp->pa_shared_dram); in platform_parse_resource()
153 return -EINVAL; in platform_parse_resource()
162 mem_region = of_parse_phandle(dev->of_node, "memory-region", 1); in platform_parse_resource()
164 dev_err(dev, "no memory-region sysmem phandle\n"); in platform_parse_resource()
165 return -ENODEV; in platform_parse_resource()
175 adsp->pa_dram = (phys_addr_t)res.start; in platform_parse_resource()
176 adsp->dramsize = resource_size(&res); in platform_parse_resource()
177 if (adsp->pa_dram & DRAM_REMAP_MASK) { in platform_parse_resource()
178 dev_err(dev, "adsp memory(%#x) is not 4K-aligned\n", in platform_parse_resource()
179 (u32)adsp->pa_dram); in platform_parse_resource()
180 return -EINVAL; in platform_parse_resource()
183 if (adsp->dramsize < TOTAL_SIZE_SHARED_DRAM_FROM_TAIL) { in platform_parse_resource()
185 adsp->dramsize); in platform_parse_resource()
186 return -EINVAL; in platform_parse_resource()
190 &adsp->pa_dram, adsp->dramsize); in platform_parse_resource()
192 /* Parse CFG base */ in platform_parse_resource()
193 mmio = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg"); in platform_parse_resource()
194 if (!mmio) { in platform_parse_resource()
195 dev_err(dev, "no ADSP-CFG register resource\n"); in platform_parse_resource()
196 return -ENXIO; in platform_parse_resource()
199 adsp->va_cfgreg = devm_ioremap_resource(dev, mmio); in platform_parse_resource()
200 if (IS_ERR(adsp->va_cfgreg)) in platform_parse_resource()
201 return PTR_ERR(adsp->va_cfgreg); in platform_parse_resource()
203 adsp->pa_cfgreg = (phys_addr_t)mmio->start; in platform_parse_resource()
204 adsp->cfgregsize = resource_size(mmio); in platform_parse_resource()
206 dev_dbg(dev, "cfgreg-vbase=%p, cfgregsize=%#x\n", in platform_parse_resource()
207 adsp->va_cfgreg, adsp->cfgregsize); in platform_parse_resource()
210 mmio = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sram"); in platform_parse_resource()
211 if (!mmio) { in platform_parse_resource()
213 return -ENXIO; in platform_parse_resource()
216 adsp->pa_sram = (phys_addr_t)mmio->start; in platform_parse_resource()
217 adsp->sramsize = resource_size(mmio); in platform_parse_resource()
218 if (adsp->sramsize < TOTAL_SIZE_SHARED_SRAM_FROM_TAIL) { in platform_parse_resource()
220 adsp->sramsize); in platform_parse_resource()
221 return -EINVAL; in platform_parse_resource()
224 dev_dbg(dev, "sram pbase=%pa,%#x\n", &adsp->pa_sram, adsp->sramsize); in platform_parse_resource()
238 return -ENOMEM; in adsp_sram_power_on()
258 return -ENXIO; in adsp_memory_remap_init()
264 return -ENOMEM; in adsp_memory_remap_init()
267 offset = adsp->pa_dram - DRAM_PHYS_BASE_FROM_DSP_VIEW; in adsp_memory_remap_init()
268 adsp->dram_offset = offset; in adsp_memory_remap_init()
270 dev_dbg(dev, "adsp->pa_dram %pa, offset %#x\n", &adsp->pa_dram, offset); in adsp_memory_remap_init()
274 return -EIO; in adsp_memory_remap_init()
282 struct device *dev = &pdev->dev; in adsp_shared_base_ioremap()
285 /* remap shared-dram base to be non-cachable */ in adsp_shared_base_ioremap()
286 adsp->shared_dram = devm_ioremap(dev, adsp->pa_shared_dram, in adsp_shared_base_ioremap()
287 adsp->shared_size); in adsp_shared_base_ioremap()
288 if (!adsp->shared_dram) { in adsp_shared_base_ioremap()
290 adsp->shared_dram, adsp->shared_size); in adsp_shared_base_ioremap()
291 return -ENOMEM; in adsp_shared_base_ioremap()
294 dev_dbg(dev, "shared-dram vbase=%p, phy addr :%pa, size=%#x\n", in adsp_shared_base_ioremap()
295 adsp->shared_dram, &adsp->pa_shared_dram, adsp->shared_size); in adsp_shared_base_ioremap()
305 dev_dbg(sdev->dev, "HIFIxDSP boot from base : 0x%08X\n", adsp_bootup_addr); in mt8195_run()
313 struct platform_device *pdev = container_of(sdev->dev, struct platform_device, dev); in mt8195_dsp_probe()
317 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in mt8195_dsp_probe()
319 return -ENOMEM; in mt8195_dsp_probe()
321 sdev->pdata->hw_pdata = priv; in mt8195_dsp_probe()
322 priv->dev = sdev->dev; in mt8195_dsp_probe()
323 priv->sdev = sdev; in mt8195_dsp_probe()
325 priv->adsp = devm_kzalloc(&pdev->dev, sizeof(struct mtk_adsp_chip_info), GFP_KERNEL); in mt8195_dsp_probe()
326 if (!priv->adsp) in mt8195_dsp_probe()
327 return -ENOMEM; in mt8195_dsp_probe()
329 ret = platform_parse_resource(pdev, priv->adsp); in mt8195_dsp_probe()
335 dev_err(sdev->dev, "mt8195_adsp_init_clock failed\n"); in mt8195_dsp_probe()
336 return -EINVAL; in mt8195_dsp_probe()
341 dev_err(sdev->dev, "adsp_clock_on fail!\n"); in mt8195_dsp_probe()
342 return -EINVAL; in mt8195_dsp_probe()
345 ret = adsp_sram_power_on(sdev->dev, true); in mt8195_dsp_probe()
347 dev_err(sdev->dev, "adsp_sram_power_on fail!\n"); in mt8195_dsp_probe()
351 ret = adsp_memory_remap_init(&pdev->dev, priv->adsp); in mt8195_dsp_probe()
353 dev_err(sdev->dev, "adsp_memory_remap_init fail!\n"); in mt8195_dsp_probe()
357 sdev->bar[SOF_FW_BLK_TYPE_IRAM] = devm_ioremap(sdev->dev, in mt8195_dsp_probe()
358 priv->adsp->pa_sram, in mt8195_dsp_probe()
359 priv->adsp->sramsize); in mt8195_dsp_probe()
360 if (!sdev->bar[SOF_FW_BLK_TYPE_IRAM]) { in mt8195_dsp_probe()
361 dev_err(sdev->dev, "failed to ioremap base %pa size %#x\n", in mt8195_dsp_probe()
362 &priv->adsp->pa_sram, priv->adsp->sramsize); in mt8195_dsp_probe()
363 ret = -EINVAL; in mt8195_dsp_probe()
367 priv->adsp->va_sram = sdev->bar[SOF_FW_BLK_TYPE_IRAM]; in mt8195_dsp_probe()
369 sdev->bar[SOF_FW_BLK_TYPE_SRAM] = devm_ioremap(sdev->dev, in mt8195_dsp_probe()
370 priv->adsp->pa_dram, in mt8195_dsp_probe()
371 priv->adsp->dramsize); in mt8195_dsp_probe()
372 if (!sdev->bar[SOF_FW_BLK_TYPE_SRAM]) { in mt8195_dsp_probe()
373 dev_err(sdev->dev, "failed to ioremap base %pa size %#x\n", in mt8195_dsp_probe()
374 &priv->adsp->pa_dram, priv->adsp->dramsize); in mt8195_dsp_probe()
375 ret = -EINVAL; in mt8195_dsp_probe()
378 priv->adsp->va_dram = sdev->bar[SOF_FW_BLK_TYPE_SRAM]; in mt8195_dsp_probe()
380 ret = adsp_shared_base_ioremap(pdev, priv->adsp); in mt8195_dsp_probe()
382 dev_err(sdev->dev, "adsp_shared_base_ioremap fail!\n"); in mt8195_dsp_probe()
386 sdev->bar[DSP_REG_BAR] = priv->adsp->va_cfgreg; in mt8195_dsp_probe()
388 sdev->mmio_bar = SOF_FW_BLK_TYPE_SRAM; in mt8195_dsp_probe()
389 sdev->mailbox_bar = SOF_FW_BLK_TYPE_SRAM; in mt8195_dsp_probe()
391 /* set default mailbox offset for FW ready message */ in mt8195_dsp_probe()
392 sdev->dsp_box.offset = mt8195_get_mailbox_offset(sdev); in mt8195_dsp_probe()
394 priv->ipc_dev = platform_device_register_data(&pdev->dev, "mtk-adsp-ipc", in mt8195_dsp_probe()
397 if (IS_ERR(priv->ipc_dev)) { in mt8195_dsp_probe()
398 ret = PTR_ERR(priv->ipc_dev); in mt8195_dsp_probe()
399 dev_err(sdev->dev, "failed to register mtk-adsp-ipc device\n"); in mt8195_dsp_probe()
403 priv->dsp_ipc = dev_get_drvdata(&priv->ipc_dev->dev); in mt8195_dsp_probe()
404 if (!priv->dsp_ipc) { in mt8195_dsp_probe()
405 ret = -EPROBE_DEFER; in mt8195_dsp_probe()
406 dev_err(sdev->dev, "failed to get drvdata\n"); in mt8195_dsp_probe()
410 mtk_adsp_ipc_set_data(priv->dsp_ipc, priv); in mt8195_dsp_probe()
411 priv->dsp_ipc->ops = &dsp_ops; in mt8195_dsp_probe()
416 platform_device_unregister(priv->ipc_dev); in mt8195_dsp_probe()
418 adsp_sram_power_on(&pdev->dev, false); in mt8195_dsp_probe()
427 return snd_sof_suspend(sdev->dev); in mt8195_dsp_shutdown()
432 struct platform_device *pdev = container_of(sdev->dev, struct platform_device, dev); in mt8195_dsp_remove()
433 struct adsp_priv *priv = sdev->pdata->hw_pdata; in mt8195_dsp_remove()
435 platform_device_unregister(priv->ipc_dev); in mt8195_dsp_remove()
436 adsp_sram_power_on(&pdev->dev, false); in mt8195_dsp_remove()
444 struct platform_device *pdev = container_of(sdev->dev, struct platform_device, dev); in mt8195_dsp_suspend()
456 dev_warn(sdev->dev, "dsp not idle, powering off anyway : swrest %#x, pc %#x, ret %d\n", in mt8195_dsp_suspend()
464 ret = adsp_sram_power_on(&pdev->dev, false); in mt8195_dsp_suspend()
466 dev_err(sdev->dev, "adsp_sram_power_off fail!\n"); in mt8195_dsp_suspend()
481 dev_err(sdev->dev, "adsp_clock_on fail!\n"); in mt8195_dsp_resume()
486 ret = adsp_sram_power_on(sdev->dev, true); in mt8195_dsp_resume()
488 dev_err(sdev->dev, "adsp_sram_power_on fail!\n"); in mt8195_dsp_resume()
504 platform_params->cont_update_posn = 1; in mt8195_pcm_hw_params()
517 struct snd_soc_component *scomp = sdev->component; in mt8195_pcm_pointer()
522 dev_warn_ratelimited(sdev->dev, "warn: can't find PCM with DAI ID %d\n", in mt8195_pcm_pointer()
523 rtd->dai_link->id); in mt8195_pcm_pointer()
527 stream = &spcm->stream[substream->stream]; in mt8195_pcm_pointer()
528 ret = snd_sof_ipc_msg_data(sdev, stream->substream, &posn, sizeof(posn)); in mt8195_pcm_pointer()
530 dev_warn(sdev->dev, "failed to read stream position: %d\n", ret); in mt8195_pcm_pointer()
534 memcpy(&stream->posn, &posn, sizeof(posn)); in mt8195_pcm_pointer()
535 pos = spcm->stream[substream->stream].posn.host_posn; in mt8195_pcm_pointer()
536 pos = bytes_to_frames(substream->runtime, pos); in mt8195_pcm_pointer()
558 dev_info(sdev->dev, "adsp dump : pc %#x, data %#x, bus0 %#x, bus1 %#x, swrest %#x", in mt8195_adsp_dump()
560 dev_info(sdev->dev, "dbg_inst %#x, ls0stat %#x, ls1stat %#x, faultbus %#x, faultinfo %#x", in mt8195_adsp_dump()
665 .sof_tplg_filename = "sof-mt8195-mt6359-rt1019-rt5682-dts.tplg"
668 .sof_tplg_filename = "sof-mt8195.tplg"
682 [SOF_IPC] = "mediatek/sof-tplg",
685 [SOF_IPC] = "sof-mt8195.ri",
687 .nocodec_tplg_filename = "sof-mt8195-nocodec.tplg",
693 { .compatible = "mediatek,mt8195-dsp", .data = &sof_of_mt8195_desc},
704 .name = "sof-audio-of-mt8195",