xref: /openbmc/linux/sound/soc/sof/imx/imx-common.c (revision 5c816641)
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2 //
3 // Copyright 2020 NXP
4 //
5 // Common helpers for the audio DSP on i.MX8
6 
7 #include <linux/module.h>
8 #include <sound/sof/xtensa.h>
9 #include "../ops.h"
10 
11 #include "imx-common.h"
12 
13 /**
14  * imx8_get_registers() - This function is called in case of DSP oops
15  * in order to gather information about the registers, filename and
16  * linenumber and stack.
17  * @sdev: SOF device
18  * @xoops: Stores information about registers.
19  * @panic_info: Stores information about filename and line number.
20  * @stack: Stores the stack dump.
21  * @stack_words: Size of the stack dump.
22  */
23 void imx8_get_registers(struct snd_sof_dev *sdev,
24 			struct sof_ipc_dsp_oops_xtensa *xoops,
25 			struct sof_ipc_panic_info *panic_info,
26 			u32 *stack, size_t stack_words)
27 {
28 	u32 offset = sdev->dsp_oops_offset;
29 
30 	/* first read registers */
31 	sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops));
32 
33 	/* then get panic info */
34 	if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) {
35 		dev_err(sdev->dev, "invalid header size 0x%x. FW oops is bogus\n",
36 			xoops->arch_hdr.totalsize);
37 		return;
38 	}
39 	offset += xoops->arch_hdr.totalsize;
40 	sof_mailbox_read(sdev, offset, panic_info, sizeof(*panic_info));
41 
42 	/* then get the stack */
43 	offset += sizeof(*panic_info);
44 	sof_mailbox_read(sdev, offset, stack, stack_words * sizeof(u32));
45 }
46 
47 /**
48  * imx8_dump() - This function is called when a panic message is
49  * received from the firmware.
50  * @sdev: SOF device
51  * @flags: parameter not used but required by ops prototype
52  */
53 void imx8_dump(struct snd_sof_dev *sdev, u32 flags)
54 {
55 	struct sof_ipc_dsp_oops_xtensa xoops;
56 	struct sof_ipc_panic_info panic_info;
57 	u32 stack[IMX8_STACK_DUMP_SIZE];
58 	u32 status;
59 
60 	/* Get information about the panic status from the debug box area.
61 	 * Compute the trace point based on the status.
62 	 */
63 	sof_mailbox_read(sdev, sdev->debug_box.offset + 0x4, &status, 4);
64 
65 	/* Get information about the registers, the filename and line
66 	 * number and the stack.
67 	 */
68 	imx8_get_registers(sdev, &xoops, &panic_info, stack,
69 			   IMX8_STACK_DUMP_SIZE);
70 
71 	/* Print the information to the console */
72 	sof_print_oops_and_stack(sdev, KERN_ERR, status, status, &xoops,
73 				 &panic_info, stack, IMX8_STACK_DUMP_SIZE);
74 }
75 EXPORT_SYMBOL(imx8_dump);
76 
77 int imx8_parse_clocks(struct snd_sof_dev *sdev, struct imx_clocks *clks)
78 {
79 	int ret;
80 
81 	ret = devm_clk_bulk_get(sdev->dev, clks->num_dsp_clks, clks->dsp_clks);
82 	if (ret)
83 		dev_err(sdev->dev, "Failed to request DSP clocks\n");
84 
85 	return ret;
86 }
87 EXPORT_SYMBOL(imx8_parse_clocks);
88 
89 int imx8_enable_clocks(struct snd_sof_dev *sdev, struct imx_clocks *clks)
90 {
91 	return clk_bulk_prepare_enable(clks->num_dsp_clks, clks->dsp_clks);
92 }
93 EXPORT_SYMBOL(imx8_enable_clocks);
94 
95 void imx8_disable_clocks(struct snd_sof_dev *sdev, struct imx_clocks *clks)
96 {
97 	clk_bulk_disable_unprepare(clks->num_dsp_clks, clks->dsp_clks);
98 }
99 EXPORT_SYMBOL(imx8_disable_clocks);
100 
101 MODULE_LICENSE("Dual BSD/GPL");
102