q6audio_v2.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2012-2013, 2015-2017, 2020 The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/module.h>
  6. #include <linux/fs.h>
  7. #include <linux/miscdevice.h>
  8. #include <linux/uaccess.h>
  9. #include <linux/sched.h>
  10. #include <linux/wait.h>
  11. #include <linux/dma-mapping.h>
  12. #include <linux/slab.h>
  13. #include <linux/atomic.h>
  14. #include <asm/ioctls.h>
  15. #include "audio_utils.h"
  16. void q6asm_in_cb(uint32_t opcode, uint32_t token,
  17. uint32_t *payload, void *priv)
  18. {
  19. struct q6audio_in *audio = (struct q6audio_in *)priv;
  20. unsigned long flags;
  21. unsigned long en_de_flags;
  22. spin_lock_irqsave(&enc_dec_lock, en_de_flags);
  23. if (audio == NULL) {
  24. pr_err("%s: failed to get q6audio value\n", __func__);
  25. goto error;
  26. }
  27. pr_debug("%s:session id %d: opcode[0x%x]\n", __func__,
  28. audio->ac->session, opcode);
  29. spin_lock_irqsave(&audio->dsp_lock, flags);
  30. switch (opcode) {
  31. case ASM_DATA_EVENT_READ_DONE_V2:
  32. audio_in_get_dsp_frames(audio, token, payload);
  33. break;
  34. case ASM_DATA_EVENT_WRITE_DONE_V2:
  35. atomic_inc(&audio->in_count);
  36. wake_up(&audio->write_wait);
  37. break;
  38. case ASM_DATA_EVENT_RENDERED_EOS:
  39. case ASM_DATA_EVENT_RENDERED_EOS_V2:
  40. audio->eos_rsp = 1;
  41. wake_up(&audio->read_wait);
  42. break;
  43. case ASM_STREAM_CMDRSP_GET_PP_PARAMS_V2:
  44. break;
  45. case ASM_SESSION_EVENTX_OVERFLOW:
  46. pr_err("%s:session id %d: ASM_SESSION_EVENT_TX_OVERFLOW\n",
  47. __func__, audio->ac->session);
  48. break;
  49. case RESET_EVENTS:
  50. pr_debug("%s:received RESET EVENTS\n", __func__);
  51. audio->enabled = 0;
  52. audio->stopped = 1;
  53. audio->event_abort = 1;
  54. audio->reset_event = true;
  55. wake_up(&audio->read_wait);
  56. wake_up(&audio->write_wait);
  57. break;
  58. default:
  59. pr_debug("%s:session id %d: Ignore opcode[0x%x]\n", __func__,
  60. audio->ac->session, opcode);
  61. break;
  62. }
  63. spin_unlock_irqrestore(&audio->dsp_lock, flags);
  64. error:
  65. spin_unlock_irqrestore(&enc_dec_lock, en_de_flags);
  66. }
  67. void audio_in_get_dsp_frames(void *priv,
  68. uint32_t token, uint32_t *payload)
  69. {
  70. struct q6audio_in *audio = (struct q6audio_in *)priv;
  71. uint32_t index;
  72. index = q6asm_get_buf_index_from_token(token);
  73. pr_debug("%s:session id %d: index=%d nr frames=%d offset[%d]\n",
  74. __func__, audio->ac->session, token, payload[9],
  75. payload[5]);
  76. pr_debug("%s:session id %d: timemsw=%d lsw=%d\n", __func__,
  77. audio->ac->session, payload[7], payload[6]);
  78. pr_debug("%s:session id %d: uflags=0x%8x uid=0x%8x\n", __func__,
  79. audio->ac->session, payload[8], payload[10]);
  80. pr_debug("%s:session id %d: enc_framesotal_size=0x%8x\n", __func__,
  81. audio->ac->session, payload[4]);
  82. /* Ensure the index is within max array size: FRAME_NUM */
  83. if (index >= FRAME_NUM) {
  84. pr_err("%s: Invalid index %d\n",
  85. __func__, index);
  86. return;
  87. }
  88. audio->out_frame_info[index][0] = payload[9];
  89. audio->out_frame_info[index][1] = payload[5];
  90. /* statistics of read */
  91. atomic_add(payload[4], &audio->in_bytes);
  92. atomic_add(payload[9], &audio->in_samples);
  93. if (atomic_read(&audio->out_count) <= audio->str_cfg.buffer_count) {
  94. atomic_inc(&audio->out_count);
  95. wake_up(&audio->read_wait);
  96. }
  97. }