q6audio_v2.c 2.7 KB

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