118ebffe4SIulian Olaru // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
218ebffe4SIulian Olaru //
318ebffe4SIulian Olaru // Copyright 2020 NXP
418ebffe4SIulian Olaru //
518ebffe4SIulian Olaru // Common helpers for the audio DSP on i.MX8
618ebffe4SIulian Olaru
75b51b922SKai Vehmanen #include <linux/module.h>
818ebffe4SIulian Olaru #include <sound/sof/xtensa.h>
918ebffe4SIulian Olaru #include "../ops.h"
1018ebffe4SIulian Olaru
1118ebffe4SIulian Olaru #include "imx-common.h"
1218ebffe4SIulian Olaru
1318ebffe4SIulian Olaru /**
1418ebffe4SIulian Olaru * imx8_get_registers() - This function is called in case of DSP oops
1518ebffe4SIulian Olaru * in order to gather information about the registers, filename and
1618ebffe4SIulian Olaru * linenumber and stack.
1718ebffe4SIulian Olaru * @sdev: SOF device
1818ebffe4SIulian Olaru * @xoops: Stores information about registers.
1918ebffe4SIulian Olaru * @panic_info: Stores information about filename and line number.
2018ebffe4SIulian Olaru * @stack: Stores the stack dump.
2118ebffe4SIulian Olaru * @stack_words: Size of the stack dump.
2218ebffe4SIulian Olaru */
imx8_get_registers(struct snd_sof_dev * sdev,struct sof_ipc_dsp_oops_xtensa * xoops,struct sof_ipc_panic_info * panic_info,u32 * stack,size_t stack_words)2318ebffe4SIulian Olaru void imx8_get_registers(struct snd_sof_dev *sdev,
2418ebffe4SIulian Olaru struct sof_ipc_dsp_oops_xtensa *xoops,
2518ebffe4SIulian Olaru struct sof_ipc_panic_info *panic_info,
2618ebffe4SIulian Olaru u32 *stack, size_t stack_words)
2718ebffe4SIulian Olaru {
2818ebffe4SIulian Olaru u32 offset = sdev->dsp_oops_offset;
2918ebffe4SIulian Olaru
3018ebffe4SIulian Olaru /* first read registers */
3118ebffe4SIulian Olaru sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops));
3218ebffe4SIulian Olaru
3318ebffe4SIulian Olaru /* then get panic info */
3418ebffe4SIulian Olaru if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) {
3518ebffe4SIulian Olaru dev_err(sdev->dev, "invalid header size 0x%x. FW oops is bogus\n",
3618ebffe4SIulian Olaru xoops->arch_hdr.totalsize);
3718ebffe4SIulian Olaru return;
3818ebffe4SIulian Olaru }
3918ebffe4SIulian Olaru offset += xoops->arch_hdr.totalsize;
4018ebffe4SIulian Olaru sof_mailbox_read(sdev, offset, panic_info, sizeof(*panic_info));
4118ebffe4SIulian Olaru
4218ebffe4SIulian Olaru /* then get the stack */
4318ebffe4SIulian Olaru offset += sizeof(*panic_info);
4418ebffe4SIulian Olaru sof_mailbox_read(sdev, offset, stack, stack_words * sizeof(u32));
4518ebffe4SIulian Olaru }
4618ebffe4SIulian Olaru
4718ebffe4SIulian Olaru /**
4818ebffe4SIulian Olaru * imx8_dump() - This function is called when a panic message is
4918ebffe4SIulian Olaru * received from the firmware.
5045c29d9aSPierre-Louis Bossart * @sdev: SOF device
5145c29d9aSPierre-Louis Bossart * @flags: parameter not used but required by ops prototype
5218ebffe4SIulian Olaru */
imx8_dump(struct snd_sof_dev * sdev,u32 flags)5318ebffe4SIulian Olaru void imx8_dump(struct snd_sof_dev *sdev, u32 flags)
5418ebffe4SIulian Olaru {
5518ebffe4SIulian Olaru struct sof_ipc_dsp_oops_xtensa xoops;
5618ebffe4SIulian Olaru struct sof_ipc_panic_info panic_info;
5718ebffe4SIulian Olaru u32 stack[IMX8_STACK_DUMP_SIZE];
5818ebffe4SIulian Olaru u32 status;
5918ebffe4SIulian Olaru
6018ebffe4SIulian Olaru /* Get information about the panic status from the debug box area.
6118ebffe4SIulian Olaru * Compute the trace point based on the status.
6218ebffe4SIulian Olaru */
6318ebffe4SIulian Olaru sof_mailbox_read(sdev, sdev->debug_box.offset + 0x4, &status, 4);
6418ebffe4SIulian Olaru
6518ebffe4SIulian Olaru /* Get information about the registers, the filename and line
6618ebffe4SIulian Olaru * number and the stack.
6718ebffe4SIulian Olaru */
6818ebffe4SIulian Olaru imx8_get_registers(sdev, &xoops, &panic_info, stack,
6918ebffe4SIulian Olaru IMX8_STACK_DUMP_SIZE);
7018ebffe4SIulian Olaru
7118ebffe4SIulian Olaru /* Print the information to the console */
72*4995ffceSPeter Ujfalusi sof_print_oops_and_stack(sdev, KERN_ERR, status, status, &xoops,
73*4995ffceSPeter Ujfalusi &panic_info, stack, IMX8_STACK_DUMP_SIZE);
7418ebffe4SIulian Olaru }
7518ebffe4SIulian Olaru EXPORT_SYMBOL(imx8_dump);
765b51b922SKai Vehmanen
imx8_parse_clocks(struct snd_sof_dev * sdev,struct imx_clocks * clks)778253aa47SDaniel Baluta int imx8_parse_clocks(struct snd_sof_dev *sdev, struct imx_clocks *clks)
788253aa47SDaniel Baluta {
798253aa47SDaniel Baluta int ret;
808253aa47SDaniel Baluta
818253aa47SDaniel Baluta ret = devm_clk_bulk_get(sdev->dev, clks->num_dsp_clks, clks->dsp_clks);
828253aa47SDaniel Baluta if (ret)
838253aa47SDaniel Baluta dev_err(sdev->dev, "Failed to request DSP clocks\n");
848253aa47SDaniel Baluta
858253aa47SDaniel Baluta return ret;
868253aa47SDaniel Baluta }
878253aa47SDaniel Baluta EXPORT_SYMBOL(imx8_parse_clocks);
888253aa47SDaniel Baluta
imx8_enable_clocks(struct snd_sof_dev * sdev,struct imx_clocks * clks)898253aa47SDaniel Baluta int imx8_enable_clocks(struct snd_sof_dev *sdev, struct imx_clocks *clks)
908253aa47SDaniel Baluta {
918253aa47SDaniel Baluta return clk_bulk_prepare_enable(clks->num_dsp_clks, clks->dsp_clks);
928253aa47SDaniel Baluta }
938253aa47SDaniel Baluta EXPORT_SYMBOL(imx8_enable_clocks);
948253aa47SDaniel Baluta
imx8_disable_clocks(struct snd_sof_dev * sdev,struct imx_clocks * clks)958253aa47SDaniel Baluta void imx8_disable_clocks(struct snd_sof_dev *sdev, struct imx_clocks *clks)
968253aa47SDaniel Baluta {
978253aa47SDaniel Baluta clk_bulk_disable_unprepare(clks->num_dsp_clks, clks->dsp_clks);
988253aa47SDaniel Baluta }
998253aa47SDaniel Baluta EXPORT_SYMBOL(imx8_disable_clocks);
1008253aa47SDaniel Baluta
1015b51b922SKai Vehmanen MODULE_LICENSE("Dual BSD/GPL");
102