imx-common.c 2.9 KB

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