q6audio_v2.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. spin_lock(&enc_dec_lock);
  22. if (audio == NULL) {
  23. pr_err("%s: failed to get q6audio value\n", __func__);
  24. goto error;
  25. }
  26. pr_debug("%s:session id %d: opcode[0x%x]\n", __func__,
  27. audio->ac->session, opcode);
  28. spin_lock_irqsave(&audio->dsp_lock, flags);
  29. switch (opcode) {
  30. case ASM_DATA_EVENT_READ_DONE_V2:
  31. audio_in_get_dsp_frames(audio, token, payload);
  32. break;
  33. case ASM_DATA_EVENT_WRITE_DONE_V2:
  34. atomic_inc(&audio->in_count);
  35. wake_up(&audio->write_wait);
  36. break;
  37. case ASM_DATA_EVENT_RENDERED_EOS:
  38. case ASM_DATA_EVENT_RENDERED_EOS_V2:
  39. audio->eos_rsp = 1;
  40. wake_up(&audio->read_wait);
  41. break;
  42. case ASM_STREAM_CMDRSP_GET_PP_PARAMS_V2:
  43. break;
  44. case ASM_SESSION_EVENTX_OVERFLOW:
  45. pr_err("%s:session id %d: ASM_SESSION_EVENT_TX_OVERFLOW\n",
  46. __func__, audio->ac->session);
  47. break;
  48. case RESET_EVENTS:
  49. pr_debug("%s:received RESET EVENTS\n", __func__);
  50. audio->enabled = 0;
  51. audio->stopped = 1;
  52. audio->event_abort = 1;
  53. audio->reset_event = true;
  54. wake_up(&audio->read_wait);
  55. wake_up(&audio->write_wait);
  56. break;
  57. default:
  58. pr_debug("%s:session id %d: Ignore opcode[0x%x]\n", __func__,
  59. audio->ac->session, opcode);
  60. break;
  61. }
  62. spin_unlock_irqrestore(&audio->dsp_lock, flags);
  63. error:
  64. spin_unlock(&enc_dec_lock);
  65. }
  66. void audio_in_get_dsp_frames(void *priv,
  67. uint32_t token, uint32_t *payload)
  68. {
  69. struct q6audio_in *audio = (struct q6audio_in *)priv;
  70. uint32_t index;
  71. index = q6asm_get_buf_index_from_token(token);
  72. pr_debug("%s:session id %d: index=%d nr frames=%d offset[%d]\n",
  73. __func__, audio->ac->session, token, payload[9],
  74. payload[5]);
  75. pr_debug("%s:session id %d: timemsw=%d lsw=%d\n", __func__,
  76. audio->ac->session, payload[7], payload[6]);
  77. pr_debug("%s:session id %d: uflags=0x%8x uid=0x%8x\n", __func__,
  78. audio->ac->session, payload[8], payload[10]);
  79. pr_debug("%s:session id %d: enc_framesotal_size=0x%8x\n", __func__,
  80. audio->ac->session, payload[4]);
  81. /* Ensure the index is within max array size: FRAME_NUM */
  82. if (index >= FRAME_NUM) {
  83. pr_err("%s: Invalid index %d\n",
  84. __func__, index);
  85. return;
  86. }
  87. audio->out_frame_info[index][0] = payload[9];
  88. audio->out_frame_info[index][1] = payload[5];
  89. /* statistics of read */
  90. atomic_add(payload[4], &audio->in_bytes);
  91. atomic_add(payload[9], &audio->in_samples);
  92. if (atomic_read(&audio->out_count) <= audio->str_cfg.buffer_count) {
  93. atomic_inc(&audio->out_count);
  94. wake_up(&audio->read_wait);
  95. }
  96. }