Lines Matching +full:dt +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"
27 #include "../mtk-adsp-common.h"
29 #include "mt8186-clk.h"
44 struct adsp_priv *priv = sdev->pdata->hw_pdata; in mt8186_send_msg()
46 sof_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data, in mt8186_send_msg()
47 msg->msg_size); in mt8186_send_msg()
49 return mtk_adsp_ipc_send(priv->dsp_ipc, MTK_ADSP_IPC_REQ, MTK_ADSP_IPC_OP_REQ); in mt8186_send_msg()
57 spin_lock_irqsave(&priv->sdev->ipc_lock, flags); in mt8186_dsp_handle_reply()
58 snd_sof_ipc_process_reply(priv->sdev, 0); in mt8186_dsp_handle_reply()
59 spin_unlock_irqrestore(&priv->sdev->ipc_lock, flags); in mt8186_dsp_handle_reply()
69 sof_mailbox_read(priv->sdev, priv->sdev->debug_box.offset + 4, in mt8186_dsp_handle_request()
74 snd_sof_dsp_panic(priv->sdev, p, true); in mt8186_dsp_handle_request()
76 snd_sof_ipc_msgs_rx(priv->sdev); in mt8186_dsp_handle_request()
79 ret = mtk_adsp_ipc_send(priv->dsp_ipc, MTK_ADSP_IPC_RSP, MTK_ADSP_IPC_OP_RSP); in mt8186_dsp_handle_request()
81 dev_err(priv->dev, "request send ipc failed"); in mt8186_dsp_handle_request()
92 struct resource *mmio; in platform_parse_resource() local
95 struct device *dev = &pdev->dev; in platform_parse_resource()
105 mem_region = of_parse_phandle(dev->of_node, "memory-region", 1); in platform_parse_resource()
107 dev_err(dev, "no memory-region sysmem phandle\n"); in platform_parse_resource()
108 return -ENODEV; in platform_parse_resource()
118 adsp->pa_dram = (phys_addr_t)res.start; in platform_parse_resource()
119 if (adsp->pa_dram & DRAM_REMAP_MASK) { in platform_parse_resource()
120 dev_err(dev, "adsp memory(%#x) is not 4K-aligned\n", in platform_parse_resource()
121 (u32)adsp->pa_dram); in platform_parse_resource()
122 return -EINVAL; in platform_parse_resource()
125 adsp->dramsize = resource_size(&res); in platform_parse_resource()
126 if (adsp->dramsize < TOTAL_SIZE_SHARED_DRAM_FROM_TAIL) { in platform_parse_resource()
128 adsp->dramsize); in platform_parse_resource()
129 return -EINVAL; in platform_parse_resource()
132 dev_dbg(dev, "dram pbase=%pa size=%#x\n", &adsp->pa_dram, adsp->dramsize); in platform_parse_resource()
134 mmio = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg"); in platform_parse_resource()
135 if (!mmio) { in platform_parse_resource()
136 dev_err(dev, "no ADSP-CFG register resource\n"); in platform_parse_resource()
137 return -ENXIO; in platform_parse_resource()
140 adsp->va_cfgreg = devm_ioremap_resource(dev, mmio); in platform_parse_resource()
141 if (IS_ERR(adsp->va_cfgreg)) in platform_parse_resource()
142 return PTR_ERR(adsp->va_cfgreg); in platform_parse_resource()
144 adsp->pa_cfgreg = (phys_addr_t)mmio->start; in platform_parse_resource()
145 adsp->cfgregsize = resource_size(mmio); in platform_parse_resource()
147 dev_dbg(dev, "cfgreg pbase=%pa size=%#x\n", &adsp->pa_cfgreg, adsp->cfgregsize); in platform_parse_resource()
149 mmio = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sram"); in platform_parse_resource()
150 if (!mmio) { in platform_parse_resource()
152 return -ENXIO; in platform_parse_resource()
155 adsp->pa_sram = (phys_addr_t)mmio->start; in platform_parse_resource()
156 adsp->sramsize = resource_size(mmio); in platform_parse_resource()
158 dev_dbg(dev, "sram pbase=%pa size=%#x\n", &adsp->pa_sram, adsp->sramsize); in platform_parse_resource()
160 mmio = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sec"); in platform_parse_resource()
161 if (!mmio) { in platform_parse_resource()
163 return -ENXIO; in platform_parse_resource()
166 adsp->va_secreg = devm_ioremap_resource(dev, mmio); in platform_parse_resource()
167 if (IS_ERR(adsp->va_secreg)) in platform_parse_resource()
168 return PTR_ERR(adsp->va_secreg); in platform_parse_resource()
170 adsp->pa_secreg = (phys_addr_t)mmio->start; in platform_parse_resource()
171 adsp->secregsize = resource_size(mmio); in platform_parse_resource()
173 dev_dbg(dev, "secreg pbase=%pa size=%#x\n", &adsp->pa_secreg, adsp->secregsize); in platform_parse_resource()
175 mmio = platform_get_resource_byname(pdev, IORESOURCE_MEM, "bus"); in platform_parse_resource()
176 if (!mmio) { in platform_parse_resource()
178 return -ENXIO; in platform_parse_resource()
181 adsp->va_busreg = devm_ioremap_resource(dev, mmio); in platform_parse_resource()
182 if (IS_ERR(adsp->va_busreg)) in platform_parse_resource()
183 return PTR_ERR(adsp->va_busreg); in platform_parse_resource()
185 adsp->pa_busreg = (phys_addr_t)mmio->start; in platform_parse_resource()
186 adsp->busregsize = resource_size(mmio); in platform_parse_resource()
188 dev_dbg(dev, "busreg pbase=%pa size=%#x\n", &adsp->pa_busreg, adsp->busregsize); in platform_parse_resource()
210 offset = adsp->pa_dram - DRAM_PHYS_BASE_FROM_DSP_VIEW; in adsp_memory_remap_init()
211 adsp->dram_offset = offset; in adsp_memory_remap_init()
214 dev_dbg(sdev->dev, "adsp->pa_dram %pa, offset %#x\n", &adsp->pa_dram, offset); in adsp_memory_remap_init()
221 dev_err(sdev->dev, "emi remap fail\n"); in adsp_memory_remap_init()
222 return -EIO; in adsp_memory_remap_init()
233 dev_dbg(sdev->dev, "HIFIxDSP boot from base : 0x%08X\n", adsp_bootup_addr); in mt8186_run()
241 struct platform_device *pdev = container_of(sdev->dev, struct platform_device, dev); in mt8186_dsp_probe()
245 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in mt8186_dsp_probe()
247 return -ENOMEM; in mt8186_dsp_probe()
249 sdev->pdata->hw_pdata = priv; in mt8186_dsp_probe()
250 priv->dev = sdev->dev; in mt8186_dsp_probe()
251 priv->sdev = sdev; in mt8186_dsp_probe()
253 priv->adsp = devm_kzalloc(&pdev->dev, sizeof(struct mtk_adsp_chip_info), GFP_KERNEL); in mt8186_dsp_probe()
254 if (!priv->adsp) in mt8186_dsp_probe()
255 return -ENOMEM; in mt8186_dsp_probe()
257 ret = platform_parse_resource(pdev, priv->adsp); in mt8186_dsp_probe()
261 sdev->bar[SOF_FW_BLK_TYPE_IRAM] = devm_ioremap(sdev->dev, in mt8186_dsp_probe()
262 priv->adsp->pa_sram, in mt8186_dsp_probe()
263 priv->adsp->sramsize); in mt8186_dsp_probe()
264 if (!sdev->bar[SOF_FW_BLK_TYPE_IRAM]) { in mt8186_dsp_probe()
265 dev_err(sdev->dev, "failed to ioremap base %pa size %#x\n", in mt8186_dsp_probe()
266 &priv->adsp->pa_sram, priv->adsp->sramsize); in mt8186_dsp_probe()
267 return -ENOMEM; in mt8186_dsp_probe()
270 priv->adsp->va_sram = sdev->bar[SOF_FW_BLK_TYPE_IRAM]; in mt8186_dsp_probe()
272 sdev->bar[SOF_FW_BLK_TYPE_SRAM] = devm_ioremap(sdev->dev, in mt8186_dsp_probe()
273 priv->adsp->pa_dram, in mt8186_dsp_probe()
274 priv->adsp->dramsize); in mt8186_dsp_probe()
276 if (!sdev->bar[SOF_FW_BLK_TYPE_SRAM]) { in mt8186_dsp_probe()
277 dev_err(sdev->dev, "failed to ioremap base %pa size %#x\n", in mt8186_dsp_probe()
278 &priv->adsp->pa_dram, priv->adsp->dramsize); in mt8186_dsp_probe()
279 return -ENOMEM; in mt8186_dsp_probe()
282 priv->adsp->va_dram = sdev->bar[SOF_FW_BLK_TYPE_SRAM]; in mt8186_dsp_probe()
284 sdev->bar[DSP_REG_BAR] = priv->adsp->va_cfgreg; in mt8186_dsp_probe()
285 sdev->bar[DSP_SECREG_BAR] = priv->adsp->va_secreg; in mt8186_dsp_probe()
286 sdev->bar[DSP_BUSREG_BAR] = priv->adsp->va_busreg; in mt8186_dsp_probe()
288 sdev->mmio_bar = SOF_FW_BLK_TYPE_SRAM; in mt8186_dsp_probe()
289 sdev->mailbox_bar = SOF_FW_BLK_TYPE_SRAM; in mt8186_dsp_probe()
292 sdev->dsp_box.offset = mt8186_get_mailbox_offset(sdev); in mt8186_dsp_probe()
294 ret = adsp_memory_remap_init(sdev, priv->adsp); in mt8186_dsp_probe()
296 dev_err(sdev->dev, "adsp_memory_remap_init fail!\n"); in mt8186_dsp_probe()
303 dev_err(sdev->dev, "mt8186_adsp_init_clock failed\n"); in mt8186_dsp_probe()
309 dev_err(sdev->dev, "mt8186_adsp_clock_on fail!\n"); in mt8186_dsp_probe()
315 priv->ipc_dev = platform_device_register_data(&pdev->dev, "mtk-adsp-ipc", in mt8186_dsp_probe()
318 if (IS_ERR(priv->ipc_dev)) { in mt8186_dsp_probe()
319 ret = PTR_ERR(priv->ipc_dev); in mt8186_dsp_probe()
320 dev_err(sdev->dev, "failed to create mtk-adsp-ipc device\n"); in mt8186_dsp_probe()
324 priv->dsp_ipc = dev_get_drvdata(&priv->ipc_dev->dev); in mt8186_dsp_probe()
325 if (!priv->dsp_ipc) { in mt8186_dsp_probe()
326 ret = -EPROBE_DEFER; in mt8186_dsp_probe()
327 dev_err(sdev->dev, "failed to get drvdata\n"); in mt8186_dsp_probe()
331 mtk_adsp_ipc_set_data(priv->dsp_ipc, priv); in mt8186_dsp_probe()
332 priv->dsp_ipc->ops = &dsp_ops; in mt8186_dsp_probe()
337 platform_device_unregister(priv->ipc_dev); in mt8186_dsp_probe()
347 struct adsp_priv *priv = sdev->pdata->hw_pdata; in mt8186_dsp_remove()
349 platform_device_unregister(priv->ipc_dev); in mt8186_dsp_remove()
357 return snd_sof_suspend(sdev->dev); in mt8186_dsp_shutdown()
375 dev_err(sdev->dev, "mt8186_adsp_clock_on fail!\n"); in mt8186_dsp_resume()
395 platform_params->cont_update_posn = 1; in mt8186_pcm_hw_params()
408 struct snd_soc_component *scomp = sdev->component; in mt8186_pcm_pointer()
413 dev_warn_ratelimited(sdev->dev, "warn: can't find PCM with DAI ID %d\n", in mt8186_pcm_pointer()
414 rtd->dai_link->id); in mt8186_pcm_pointer()
418 stream = &spcm->stream[substream->stream]; in mt8186_pcm_pointer()
421 dev_warn(sdev->dev, "failed to read stream position: %d\n", ret); in mt8186_pcm_pointer()
425 memcpy(&stream->posn, &posn, sizeof(posn)); in mt8186_pcm_pointer()
426 pos = spcm->stream[substream->stream].posn.host_posn; in mt8186_pcm_pointer()
427 pos = bytes_to_frames(substream->runtime, pos); in mt8186_pcm_pointer()
444 dev_info(sdev->dev, "adsp dump : pc %#x, data %#x, dbg_inst %#x,", in mt8186_adsp_dump()
446 dev_info(sdev->dev, "ls0stat %#x, status %#x, faultinfo %#x", in mt8186_adsp_dump()
552 .sof_tplg_filename = "sof-mt8186.tplg",
565 [SOF_IPC_TYPE_3] = "mediatek/sof-tplg",
568 [SOF_IPC_TYPE_3] = "sof-mt8186.ri",
570 .nocodec_tplg_filename = "sof-mt8186-nocodec.tplg",
626 .sof_tplg_filename = "sof-mt8188.tplg",
639 [SOF_IPC_TYPE_3] = "mediatek/sof-tplg",
642 [SOF_IPC_TYPE_3] = "sof-mt8188.ri",
644 .nocodec_tplg_filename = "sof-mt8188-nocodec.tplg",
650 { .compatible = "mediatek,mt8186-dsp", .data = &sof_of_mt8186_desc},
651 { .compatible = "mediatek,mt8188-dsp", .data = &sof_of_mt8188_desc},
656 /* DT driver definition */
662 .name = "sof-audio-of-mt8186",