Lines Matching +full:mt8195 +full:- +full:power

1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
9 * Hardware interface for audio DSP on mt8195
24 #include "../../sof-of-dev.h"
25 #include "../../sof-audio.h"
27 #include "../mtk-adsp-common.h"
28 #include "mt8195.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()
57 spin_lock_irqsave(&priv->sdev->ipc_lock, flags); in mt8195_dsp_handle_reply()
58 snd_sof_ipc_process_reply(priv->sdev, 0); in mt8195_dsp_handle_reply()
59 spin_unlock_irqrestore(&priv->sdev->ipc_lock, flags); in mt8195_dsp_handle_reply()
69 sof_mailbox_read(priv->sdev, priv->sdev->debug_box.offset + 4, in mt8195_dsp_handle_request()
74 snd_sof_dsp_panic(priv->sdev, p, true); in mt8195_dsp_handle_request()
76 snd_sof_ipc_msgs_rx(priv->sdev); in mt8195_dsp_handle_request()
79 ret = mtk_adsp_ipc_send(priv->dsp_ipc, MTK_ADSP_IPC_RSP, MTK_ADSP_IPC_OP_RSP); in mt8195_dsp_handle_request()
81 dev_err(priv->dev, "request send ipc failed"); in mt8195_dsp_handle_request()
95 struct device *dev = &pdev->dev; in platform_parse_resource()
99 mem_region = of_parse_phandle(dev->of_node, "memory-region", 0); in platform_parse_resource()
101 dev_err(dev, "no dma memory-region phandle\n"); in platform_parse_resource()
102 return -ENODEV; in platform_parse_resource()
114 adsp->pa_shared_dram = (phys_addr_t)res.start; in platform_parse_resource()
115 adsp->shared_size = resource_size(&res); in platform_parse_resource()
116 if (adsp->pa_shared_dram & DRAM_REMAP_MASK) { in platform_parse_resource()
117 dev_err(dev, "adsp shared dma memory(%#x) is not 4K-aligned\n", in platform_parse_resource()
118 (u32)adsp->pa_shared_dram); in platform_parse_resource()
119 return -EINVAL; in platform_parse_resource()
128 mem_region = of_parse_phandle(dev->of_node, "memory-region", 1); in platform_parse_resource()
130 dev_err(dev, "no memory-region sysmem phandle\n"); in platform_parse_resource()
131 return -ENODEV; in platform_parse_resource()
141 adsp->pa_dram = (phys_addr_t)res.start; in platform_parse_resource()
142 adsp->dramsize = resource_size(&res); in platform_parse_resource()
143 if (adsp->pa_dram & DRAM_REMAP_MASK) { in platform_parse_resource()
144 dev_err(dev, "adsp memory(%#x) is not 4K-aligned\n", in platform_parse_resource()
145 (u32)adsp->pa_dram); in platform_parse_resource()
146 return -EINVAL; in platform_parse_resource()
149 if (adsp->dramsize < TOTAL_SIZE_SHARED_DRAM_FROM_TAIL) { in platform_parse_resource()
151 adsp->dramsize); in platform_parse_resource()
152 return -EINVAL; in platform_parse_resource()
156 &adsp->pa_dram, adsp->dramsize); in platform_parse_resource()
161 dev_err(dev, "no ADSP-CFG register resource\n"); in platform_parse_resource()
162 return -ENXIO; in platform_parse_resource()
165 adsp->va_cfgreg = devm_ioremap_resource(dev, mmio); in platform_parse_resource()
166 if (IS_ERR(adsp->va_cfgreg)) in platform_parse_resource()
167 return PTR_ERR(adsp->va_cfgreg); in platform_parse_resource()
169 adsp->pa_cfgreg = (phys_addr_t)mmio->start; in platform_parse_resource()
170 adsp->cfgregsize = resource_size(mmio); in platform_parse_resource()
172 dev_dbg(dev, "cfgreg-vbase=%p, cfgregsize=%#x\n", in platform_parse_resource()
173 adsp->va_cfgreg, adsp->cfgregsize); in platform_parse_resource()
179 return -ENXIO; in platform_parse_resource()
182 adsp->pa_sram = (phys_addr_t)mmio->start; in platform_parse_resource()
183 adsp->sramsize = resource_size(mmio); in platform_parse_resource()
185 dev_dbg(dev, "sram pbase=%pa,%#x\n", &adsp->pa_sram, adsp->sramsize); in platform_parse_resource()
199 return -ENOMEM; in adsp_sram_power_on()
219 return -ENXIO; in adsp_memory_remap_init()
225 return -ENOMEM; in adsp_memory_remap_init()
228 offset = adsp->pa_dram - DRAM_PHYS_BASE_FROM_DSP_VIEW; in adsp_memory_remap_init()
229 adsp->dram_offset = offset; in adsp_memory_remap_init()
231 dev_dbg(dev, "adsp->pa_dram %pa, offset %#x\n", &adsp->pa_dram, offset); in adsp_memory_remap_init()
235 return -EIO; in adsp_memory_remap_init()
243 struct device *dev = &pdev->dev; in adsp_shared_base_ioremap()
246 /* remap shared-dram base to be non-cachable */ in adsp_shared_base_ioremap()
247 adsp->shared_dram = devm_ioremap(dev, adsp->pa_shared_dram, in adsp_shared_base_ioremap()
248 adsp->shared_size); in adsp_shared_base_ioremap()
249 if (!adsp->shared_dram) { in adsp_shared_base_ioremap()
251 adsp->shared_dram, adsp->shared_size); in adsp_shared_base_ioremap()
252 return -ENOMEM; in adsp_shared_base_ioremap()
255 dev_dbg(dev, "shared-dram vbase=%p, phy addr :%pa, size=%#x\n", in adsp_shared_base_ioremap()
256 adsp->shared_dram, &adsp->pa_shared_dram, adsp->shared_size); in adsp_shared_base_ioremap()
266 dev_dbg(sdev->dev, "HIFIxDSP boot from base : 0x%08X\n", adsp_bootup_addr); in mt8195_run()
274 struct platform_device *pdev = container_of(sdev->dev, struct platform_device, dev); in mt8195_dsp_probe()
278 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in mt8195_dsp_probe()
280 return -ENOMEM; in mt8195_dsp_probe()
282 sdev->pdata->hw_pdata = priv; in mt8195_dsp_probe()
283 priv->dev = sdev->dev; in mt8195_dsp_probe()
284 priv->sdev = sdev; in mt8195_dsp_probe()
286 priv->adsp = devm_kzalloc(&pdev->dev, sizeof(struct mtk_adsp_chip_info), GFP_KERNEL); in mt8195_dsp_probe()
287 if (!priv->adsp) in mt8195_dsp_probe()
288 return -ENOMEM; in mt8195_dsp_probe()
290 ret = platform_parse_resource(pdev, priv->adsp); in mt8195_dsp_probe()
296 dev_err(sdev->dev, "mt8195_adsp_init_clock failed\n"); in mt8195_dsp_probe()
297 return -EINVAL; in mt8195_dsp_probe()
302 dev_err(sdev->dev, "adsp_clock_on fail!\n"); in mt8195_dsp_probe()
303 return -EINVAL; in mt8195_dsp_probe()
306 ret = adsp_sram_power_on(sdev->dev, true); in mt8195_dsp_probe()
308 dev_err(sdev->dev, "adsp_sram_power_on fail!\n"); in mt8195_dsp_probe()
312 ret = adsp_memory_remap_init(&pdev->dev, priv->adsp); in mt8195_dsp_probe()
314 dev_err(sdev->dev, "adsp_memory_remap_init fail!\n"); in mt8195_dsp_probe()
318 sdev->bar[SOF_FW_BLK_TYPE_IRAM] = devm_ioremap(sdev->dev, in mt8195_dsp_probe()
319 priv->adsp->pa_sram, in mt8195_dsp_probe()
320 priv->adsp->sramsize); in mt8195_dsp_probe()
321 if (!sdev->bar[SOF_FW_BLK_TYPE_IRAM]) { in mt8195_dsp_probe()
322 dev_err(sdev->dev, "failed to ioremap base %pa size %#x\n", in mt8195_dsp_probe()
323 &priv->adsp->pa_sram, priv->adsp->sramsize); in mt8195_dsp_probe()
324 ret = -EINVAL; in mt8195_dsp_probe()
328 priv->adsp->va_sram = sdev->bar[SOF_FW_BLK_TYPE_IRAM]; in mt8195_dsp_probe()
330 sdev->bar[SOF_FW_BLK_TYPE_SRAM] = devm_ioremap(sdev->dev, in mt8195_dsp_probe()
331 priv->adsp->pa_dram, in mt8195_dsp_probe()
332 priv->adsp->dramsize); in mt8195_dsp_probe()
333 if (!sdev->bar[SOF_FW_BLK_TYPE_SRAM]) { in mt8195_dsp_probe()
334 dev_err(sdev->dev, "failed to ioremap base %pa size %#x\n", in mt8195_dsp_probe()
335 &priv->adsp->pa_dram, priv->adsp->dramsize); in mt8195_dsp_probe()
336 ret = -EINVAL; in mt8195_dsp_probe()
339 priv->adsp->va_dram = sdev->bar[SOF_FW_BLK_TYPE_SRAM]; in mt8195_dsp_probe()
341 ret = adsp_shared_base_ioremap(pdev, priv->adsp); in mt8195_dsp_probe()
343 dev_err(sdev->dev, "adsp_shared_base_ioremap fail!\n"); in mt8195_dsp_probe()
347 sdev->bar[DSP_REG_BAR] = priv->adsp->va_cfgreg; in mt8195_dsp_probe()
349 sdev->mmio_bar = SOF_FW_BLK_TYPE_SRAM; in mt8195_dsp_probe()
350 sdev->mailbox_bar = SOF_FW_BLK_TYPE_SRAM; in mt8195_dsp_probe()
353 sdev->dsp_box.offset = mt8195_get_mailbox_offset(sdev); in mt8195_dsp_probe()
355 priv->ipc_dev = platform_device_register_data(&pdev->dev, "mtk-adsp-ipc", in mt8195_dsp_probe()
358 if (IS_ERR(priv->ipc_dev)) { in mt8195_dsp_probe()
359 ret = PTR_ERR(priv->ipc_dev); in mt8195_dsp_probe()
360 dev_err(sdev->dev, "failed to register mtk-adsp-ipc device\n"); in mt8195_dsp_probe()
364 priv->dsp_ipc = dev_get_drvdata(&priv->ipc_dev->dev); in mt8195_dsp_probe()
365 if (!priv->dsp_ipc) { in mt8195_dsp_probe()
366 ret = -EPROBE_DEFER; in mt8195_dsp_probe()
367 dev_err(sdev->dev, "failed to get drvdata\n"); in mt8195_dsp_probe()
371 mtk_adsp_ipc_set_data(priv->dsp_ipc, priv); in mt8195_dsp_probe()
372 priv->dsp_ipc->ops = &dsp_ops; in mt8195_dsp_probe()
377 platform_device_unregister(priv->ipc_dev); in mt8195_dsp_probe()
379 adsp_sram_power_on(&pdev->dev, false); in mt8195_dsp_probe()
388 return snd_sof_suspend(sdev->dev); in mt8195_dsp_shutdown()
393 struct platform_device *pdev = container_of(sdev->dev, struct platform_device, dev); in mt8195_dsp_remove()
394 struct adsp_priv *priv = sdev->pdata->hw_pdata; in mt8195_dsp_remove()
396 platform_device_unregister(priv->ipc_dev); in mt8195_dsp_remove()
397 adsp_sram_power_on(&pdev->dev, false); in mt8195_dsp_remove()
405 struct platform_device *pdev = container_of(sdev->dev, struct platform_device, dev); in mt8195_dsp_suspend()
417 dev_warn(sdev->dev, "dsp not idle, powering off anyway : swrest %#x, pc %#x, ret %d\n", in mt8195_dsp_suspend()
424 /* power down adsp sram */ in mt8195_dsp_suspend()
425 ret = adsp_sram_power_on(&pdev->dev, false); in mt8195_dsp_suspend()
427 dev_err(sdev->dev, "adsp_sram_power_off fail!\n"); in mt8195_dsp_suspend()
442 dev_err(sdev->dev, "adsp_clock_on fail!\n"); in mt8195_dsp_resume()
446 /* power on adsp sram */ in mt8195_dsp_resume()
447 ret = adsp_sram_power_on(sdev->dev, true); in mt8195_dsp_resume()
449 dev_err(sdev->dev, "adsp_sram_power_on fail!\n"); in mt8195_dsp_resume()
454 /* on mt8195 there is 1 to 1 match between type and BAR idx */
465 platform_params->cont_update_posn = 1; in mt8195_pcm_hw_params()
478 struct snd_soc_component *scomp = sdev->component; in mt8195_pcm_pointer()
483 dev_warn_ratelimited(sdev->dev, "warn: can't find PCM with DAI ID %d\n", in mt8195_pcm_pointer()
484 rtd->dai_link->id); in mt8195_pcm_pointer()
488 stream = &spcm->stream[substream->stream]; in mt8195_pcm_pointer()
491 dev_warn(sdev->dev, "failed to read stream position: %d\n", ret); in mt8195_pcm_pointer()
495 memcpy(&stream->posn, &posn, sizeof(posn)); in mt8195_pcm_pointer()
496 pos = spcm->stream[substream->stream].posn.host_posn; in mt8195_pcm_pointer()
497 pos = bytes_to_frames(substream->runtime, pos); in mt8195_pcm_pointer()
519 dev_info(sdev->dev, "adsp dump : pc %#x, data %#x, bus0 %#x, bus1 %#x, swrest %#x", in mt8195_adsp_dump()
521 dev_info(sdev->dev, "dbg_inst %#x, ls0stat %#x, ls1stat %#x, faultbus %#x, faultinfo %#x", in mt8195_adsp_dump()
558 /* mt8195 ops */
627 .sof_tplg_filename = "sof-mt8195-mt6359-rt1019-rt5682.tplg"
630 .sof_tplg_filename = "sof-mt8195-mt6359-max98390-rt5682.tplg"
632 .compatible = "mediatek,mt8195",
633 .sof_tplg_filename = "sof-mt8195.tplg"
647 [SOF_IPC] = "mediatek/sof-tplg",
650 [SOF_IPC] = "sof-mt8195.ri",
652 .nocodec_tplg_filename = "sof-mt8195-nocodec.tplg",
658 { .compatible = "mediatek,mt8195-dsp", .data = &sof_of_mt8195_desc},
669 .name = "sof-audio-of-mt8195",